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