Is there anyway to force output from a program to a file immediately as the output occurs? It seems that when using > to redirect the output that the file only gets written after program terminates. Here's a simple test to demonstrate what I mean:
int main ( void )
int i = 0;
./test > test.log
If I allow the execution to terminate naturally, then test.log contains the expected output of the program. But if I killl the process with a CTRL+C, then nothing ever gets written to test.log. I persume the terminal buffers the output and only writes it to file after the program terminates, and since I kill the process it never gets a chance to write it to test.log.
Anyway, I realize that I could simply open a file handle and write to the log file from within the program, but I really don't want to do that since there are an enormous amount of "printf" calls that would need to be replaced and having to deal with the signals. Not to mention that the program must also run under windows.