当进程尚未完成时,GetExitCodeProcess() 返回 1 [英] GetExitCodeProcess() return 1 when process is not yet finished
问题描述
如果我为它创建一个进程和两个管道集,并且该进程在某个时间需要一些用户输入,则来自 Windows C API 的 GetExitCodeProcess()
总是返回 1代码>.例如,您可以使用 Windows
time
命令,这将返回:
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;
}
提前致谢.
推荐答案
GetExitCodeProcess
不返回 STILL_ACTIVE
;STILL_ACTIVE
是通过 lpExitCode
输出参数返回的退出代码.您需要测试返回的退出代码:
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;
}
这篇关于当进程尚未完成时,GetExitCodeProcess() 返回 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!