** SOLVED **
Hello All,
I'm trying to capture stdout from a child process, which I spawn. I create the pipes (to pipe stdout over), then call CreateProcess() with stdout inherited (into the parent process).
However that's not my problem, it seems that when I call ReadFile() on my stdout handle (of the process) it's blocking, so I get output, but it hangs waiting for more. Even after the child process has ended.
So my question is, how do I avoid 'hanging' even after the child process has ended? Anyway I could detect if it's still running?
Sorry if I haven't explained this very well, something like:
Code:
DWORD dwRead;
char buf[256];
while(ReadFile(hChildStdoutRdDup, buf, sizeof(buf), &dwRead, NULL) != FALSE && dwRead > 0)
{
buf[dwRead] = '\0';
MessageBox(NULL, buf, "title", 0);
}
/* the loop never breaks, even after the child process has ended */
Should I make 'hChildStdoutRdDup' non-blocking?
Full Source is here: http://pastebin.com/m130401a6 troubled area is highlighted
Thanks in advance!
EDIT: I'm such a moron, I didn't close the write end of the pipe while I was reading it, so in other words, it was going round in a big circle
** SOVLED **