GetExit codeProcess()返回1时,过程尚未结束 [英] GetExitCodeProcess() return 1 when process is not yet finished
问题描述
如果我创建了一个过程,两个管套它,这个过程在某个时间需要一些用户输入, GetExit codeProcess()
从Windows的C API返回总是 1
。举个例子,你可以利用Windows 时间
命令,这将返回:
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;
}
先谢谢了。
推荐答案
GetExit codeProcess
没有的收益的 STILL_ACTIVE
; STILL_ACTIVE
是退出code通过 lpExit code
out参数返回。你需要测试返回的退出code:
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;
}
这篇关于GetExit codeProcess()返回1时,过程尚未结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!