使用CreateProcess()启动时,cmd.exe在某些条件下不会终止 [英] cmd.exe will not terminate under certain conditions when launched with CreateProcess()

查看:220
本文介绍了使用CreateProcess()启动时,cmd.exe在某些条件下不会终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CreateProcess函数通过C程序执行cmd.exe命令。我通过检查进程退出代码是否等于除STILL_ACTIVE之外的任何内容来检查cmd.exe是否已使用GetExitCodeProcess函数终止。这适用于cmd / c echo Hello World之类的命令,但对于像cmd / c dir c:\ test这样的命令,如果目录包含60个以上的条目,cmd.exe将永远不会终止,cmd.exe将如果目录中有60个或更少的条目,则终止。有谁知道它为什么会这样?非常感谢。

I am executing cmd.exe commands via a C program with the CreateProcess function. I check to see if cmd.exe 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:\test", cmd.exe will never terminate if the directory contains more than 60 entries, cmd.exe will terminate if there are 60 or less entries in the directory. Does anyone know why it behaves like this? Thanks a lot.

推荐答案

显然我必须开始在循环中读取stdout / stderr管道,检查进程是否仍在运行,以及在进程终止后读取它。而不是在过程终止后再读它。
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.


这篇关于使用CreateProcess()启动时,cmd.exe在某些条件下不会终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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