I've a little programming related problem and I don't know how to solve it.
A console program (lets call it "prog1.exe") has the following pseudo-code:
Code:
while not (Ctrl_Break)
{
x = fetch_stats(); // Read some info
writeconsole(x); // Output the info to the console
wait(60); // Wait 60 seconds and repeat the whole process
}
I want to log the output of the program both to screen and to a file. So I wrote a little program ("tee.exe") which does:
Code:
while not (EndOfFile(StdIn))
{
c = read(StdIn); // Read one char from StdIn
write(StdOut, c); // Write one char to StdOut
write(FILE, c); // Write the same char to a file
}
In theory, executing "prog1.exe | tee.exe" would redirect all output from "prog1.exe" as input to "tee.exe", while "tee.exe" would write the input it gets to both the console and a file.
The problem is the output buffer. For performance reasons, the OS doesn't write the output of "prog1.exe" to "tee.exe" char-by-char, but waits until the output buffer is full and then writes the whole buffer to "tee.exe". Since "prog1.exe" does only output a few bytes every minute, it takes about 40 minutes before the output buffer is full and transfered to "tee.exe".
Running "prog1.exe >> output.txt" has a similar result: There is no output to the console any more und the file is also only updated when the output buffer is full.
I don't have access to "prog1.exe" or it's source code, so I can't flush the output buffer. Flushing the input buffer is not possible for some reason. The only workarounds I found for the problem describe how to flush the keyboard buffer.
Does anybody have an idea how to solve this problem?
My goal is simple:
1. See the console output in real time
2. Write the console output to a file