Here is my program.
#include <stdio.h> #include <stdlib.h> int main() { printf("Hello\n"); system("uname"); return 0; }
Here is the result.
$ gcc foo.c $ ./a.out Hello Linux
However, if I redirect the output of the program to a file, I see that the output order is reverse, i.e. Linux
prints before Hello
.
$ ./a.out > out.txt $ cat out.txt Linux Hello
Why is the output order different when redirecting?
source share