views:

358

answers:

3

Hi,

I'm trying to use CreateProcess to launch a powershell script from within 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.

+1  A: 

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.

Luke
A: 

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.

erick2red
A: 

@user233726 did you able to sort it out?i am getting the same problem :(....

Rohan