I'm using Visual C++ 2008 to work on a Windows Console project using the Windows Imaging API. Everything's working just fine except what's described below.
When the program is running, it displays the current progress of the operation by using:
[code]printf( "%d percent completed\n", (UINT)progress );[/code]
When run from the command line, the program outputs as expected below. Each line is printed to the window one after the other.
[code]
Starting operation...
10 percent completed
28 percent completed
55 percent completed
80 percent completed
100 percent completed
Finished.
[/code]
However when trying to read the stdout of the application, the entire text printed by printf() doesn't appear until AFTER the program has terminated, almost as if it's buffering.
Any idea why this is? I've tried putting fflush( stdout ) after the printf() statement, unfortunately this has no effect.
How are you trying to read stdout?
Could you replicate this in a small program? Why are you using printf in C++ instead of cout? Have you tried fprintf(stdout, ...)? Could you be a little less ambiguous with your wording, are you reading it using your eyes or another program? Are you piping it?
[QUOTE=UberMensch;34413011]I'm using Visual C++ 2008 to work on a Windows Console project using the Windows Imaging API. Everything's working just fine except what's described below.
When the program is running, it displays the current progress of the operation by using:
[code]printf( "%d percent completed\n", (UINT)progress );[/code]
When run from the command line, the program outputs as expected below. Each line is printed to the window one after the other.
[code]
Starting operation...
10 percent completed
28 percent completed
55 percent completed
80 percent completed
100 percent completed
Finished.
[/code]
However when trying to read the stdout of the application, the entire text printed by printf() doesn't appear until AFTER the program has terminated, almost as if it's buffering.
Any idea why this is? I've tried putting fflush( stdout ) after the printf() statement, unfortunately this has no effect.[/QUOTE]
fflush is sufficient to get past buffering issues with output. It sounds like you are seeing buffering on the input side of whatever program you are piping to.
For some reason I put fflush() back after my printf() and it's working. Very odd and I can't explain why it wasn't working before!
To answer your questions anyway, I'm reading the stdout by...
program.exe > text_file.txt
And in a separate window, opening up text_file.txt in notepad. This wasn't working before, but now is.
Thanks for taking a look anyway guys :)
Sorry, you need to Log In to post a reply to this thread.