#include #include // redirect stdout to a file int main(int ac, char *av[]) { int c; int fd = creat(av[1], 0600); if (fd == -1) perror("creat"), exit(-1); if (dup2(fd, 1) == -1) perror("dup2"), exit(-1); // echo stdin to stdout // stdout is redirected to file 'fd' while ((c = fgetc(stdin)) != EOF) fputc(c, stdout); }