如果我为它创建一个进程和两个管道集,并且该进程在某个时间需要一些用户输入,则Windows C API中的GetExitCodeProcess()
始终返回1
。例如,您可以使用Windows time
命令,这将返回:
The current time is: ...
Enter the new time:
然后立即退出,无需等待输入。
我不希望这个过程完成,直到它真的完成,所以我可以输入它。我该如何解决这个问题。
我已经构建了这个循环(我仍然希望能够确定何时完成处理):
for (;;)
{
/* Pipe input and output */
if (GetExitCodeProcess(...) != STILL_ACTIVE) break;
}
提前致谢。
答案 0 :(得分:12)
GetExitCodeProcess
不返回 STILL_ACTIVE
; STILL_ACTIVE
是通过lpExitCode
out参数返回的退出代码。您需要测试返回的退出代码:
DWORD exitCode = 0;
if (GetExitCodeProcess(handle, &exitCode) == FALSE)
{
// Handle GetExitCodeProcess failure
}
if (exitCode != STILL_ACTIVE)
{
break;
}