tags:

views:

39

answers:

1
while(GetExitCodeProcess(processInfo.hProcess, &exitCode)
        && exitCode == STILL_ACTIVE)
{
    ReadFile(defaultSTDIN, chBuf, 1, &dwRead, 0);
    WriteFile(writingEnd, chBuf, 1, &dwWritten, 0);
}

The problem with the code above is that even when the child process referenced through processInfo.hProcess has exited, we are still stuck in the while loop because ReadFile() is waiting for input. Whats the best way to solve this?

+3  A: 

What you need is to read the file asynchronously using the FILE_FLAG_OVERLAPPED flag when opening the file, and specifying an OVERLAPPED structure to the ReadFile function. Then you could wait on both the read operation and the process termination, and act appropriately.

yonilevy
Agree. P.S. I'm using overlapped I/O for a long time already. What's really missing is all the other file operations in asynchronous mode: opening the file, calling `SetEndOfFile` and etc.
valdo