'How can I capture output of a console app in a loop

My program runs a console program and captures the output using these functions:

CreatePipe, CreateProcess, WaitForSingleObject, ReadFile, and CloseHandle.

My program works great and displays the output in a window control.

If I am going to run a console app that will take a long time, instead of calling WaitForSingleObject, I'd like to call ReadFile within a loop and have the loop end when the console app does and the last message has been read.

All my attempts at this result in a forever loop and I have to kill the main program. Any advice would be appreciated. Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source