当CreateProcess函数启动CMD.EXE不会在一定条件下终止 [英] cmd.exe will not terminate under certain conditions when launched with the CreateProcess function

查看:698
本文介绍了当CreateProcess函数启动CMD.EXE不会在一定条件下终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过与CreateProcess函数一个C程序执行批处理命令。我检查,看看是否该过程已经在GetExit codeProcess功能终止,通过检查,看看是否进程退出code等于任何东西,除了STILL_ACTIVE。这能与命令,像CMD / C回声Hello World的,但像命令cmd / c目录C:\\ WINDOWS或CMD / C目录C:\\ WINDOWS&安培;退出,CMD.EXE将永远不会终止。按预期THR​​U命令提示符下启动这两个命令将终止。有谁知道为什么它从来没有通过的时候推出的CreateProcess会终止?非常感谢。

I am executing batch commands via a C program with the CreateProcess function. I check to see if the process has terminated with the GetExitCodeProcess function, by checking to see if the process exit code equals anything except STILL_ACTIVE. This works fine with commands like "cmd /c echo Hello World", but for commands like "cmd /c dir c:\windows" or "cmd /c dir c:\windows & exit", cmd.exe will never terminate. Either command when launched thru the command prompt will terminate as expected. Does anyone know why it never terminates when launched via CreateProcess? Thanks a lot.

推荐答案

显然,我不得不开始读它检查,看看是否进程仍在运行,以及之后的阅读回路中的标准输出/标准错误管道过程已经终止。而不是仅仅看它的进程终止后。非常感谢Wimmel张贴答案。

Apparently I have to start to read the stdout/stderr pipe in the loop which checks to see if the process is still running, as well as read it after the process has terminated. Rather than just read it after the process has terminated. Many thanks to Wimmel for posting the answer.

这篇关于当CreateProcess函数启动CMD.EXE不会在一定条件下终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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