We build complicated console-based tools that produce a lot of commentary on the console. These tools process a lot of data and so runs are expensive and we don't like to do them more often than necessary, especially during testing where we already have to run them repeatedly. During such tests, we often log the result to a file to capture this commentary for inspection: C:> [ourcommand] >log.txt When the application runs to completion, this works great.
If the application crashes (illegal memory reference, etc.), Windows nastily chops off the log file before the tail end of the commentary so we can't see what was occuring at the point of the crash. It also chops of the console output at the same place. So, when we get an truncated log file, we have to do it all again without the log file, to see the final answer. Windows doesn't seem to buffer the console output if not logging.
Is there a way to tell Windows not to buffer the console output while logging? Our application does use the (Windows) C runtime system and awhile back we used "setvbuf" as follows: setvbuf(stdout, NULL, _IONBF, 0); but to no avail.