问题描述:

If I create a process and two pipe sets for it, and that process needs at a certain time some user input, the GetExitCodeProcess() from the Windows C API returns always 1. As an example you can take the Windows time command, this will return:

The current time is: ...

Enter the new time:

And then exits immediately without waiting for input.

I don't want the process to finish until the it has really finished so I can pipe input to it. How can I solve this issue.

I have built this loop (I still want to be able to determine when to process has finished):

for (;;)

{

/* Pipe input and output */

if (GetExitCodeProcess(...) != STILL_ACTIVE) break;

}

Thanks in advance.

网友答案:

GetExitCodeProcess doesn't return STILL_ACTIVE; STILL_ACTIVE is the exit code returned via the lpExitCode out parameter. You need to test the exit code that was returned:

DWORD exitCode = 0;
if (GetExitCodeProcess(handle, &exitCode) == FALSE)
{
    // Handle GetExitCodeProcess failure
}

if (exitCode != STILL_ACTIVE)
{
    break;
}
相关阅读:
Top