GetExit codeProcess()返回1时,过程尚未结束 [英] GetExitCodeProcess() return 1 when process is not yet finished

查看:1564
本文介绍了GetExit codeProcess()返回1时,过程尚未结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建了一个过程,两个管套它,这个过程在某个时间需要一些用户输入, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆