开发者

CreateProcess, process do not terminate when redirecting std out/in/err

开发者 https://www.devze.com 2022-12-18 11:58 出处:网络
I\'m trying to use CreateProcess to launch a powershell script from with开发者_开发知识库in my application.

I'm trying to use CreateProcess to launch a powershell script from with开发者_开发知识库in my application.

I've used the Microsoft example (http://msdn.microsoft.com/en-us/library/ms682499(VS.85).aspx) to create the child process and redirect the standard out/in/err pipes.

The only issue left to solve is why the child process (powershell) do not terminate after executing the command.

If I execute the powershell process (with the command) cmd.exe it executes and exits, closing the process.

The only way of closing the powershell process right now is to run TerminateProcess on the handle, but that feels like a last resort.


Is your parent reading the child's stdout completely? If you don't read it all then I believe the child will hang. Also, if the script expects input you will have to write something to the child's stdin or else it will hang. You could attach windbg to the child and see where it is hanging; maybe it will give you an idea of where to look.


In linux if didn't redirect fully the output and the parent process is killed, the child process gets killed too. So you check windows documentation refering rearrange of child process when the parent gets killed.

0

精彩评论

暂无评论...
验证码 换一张
取 消