#include #include #include extern char **environ; // simple example of redirecting stdout int main(void) { int fd = open("message.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { perror(""); return 1; } if (dup2(fd, 1) < 0){ perror(""); return 1; } // we won't use this really. // we will write to the file.txt via fd from now on close(fd); char *echo_argv[] = {"/usr/bin/echo","My","lecturer","is","great!",NULL}; execve("/usr/bin/echo", echo_argv, environ); perror(""); return 0; }