The following simple C program:
#include <unistd.h> #include <stdio.h> int main(void) { while (1) { printf("Hello World\n"); sleep(1); } }
Create and run it, the terminal will print " Hello World ":
$ ./a.out Hello World Hello World Hello World
But if stdout redirected to a file, then after a run, there is still nothing in the file:
$ ./a.out > log.txt ^C $ cat log.txt $
Why is printf output to a file that stdout redirected to?
source share