CreateProcess flags on windows


#1

Does anyone know of a wrapper around the windows CreateProcess API? I’m trying to figure out how to get my new process to remain running after the parent process exits, and I think I need to play with some of the process creation flags in CreateProcess (DETACHED_PROCESS is what I think I Need)

THanks!


Job control on Windows
#2

Ahh, so close! The stdlib process can almost do what I need: there is code to set the DETACHED_PROCESS option, but the self.detach flag is hard-coded to false!


#3

i wonder if exposing this flag might be a good candidate for a future CommandExt extension trait


#4

I had this same problem! I filed an issue just recently and feedback was positive:

I might try to find time to implement it. In the meantime you’re welcome to copy the code I wrote to manually call CreateProcess with the DETACHED_PROCESS flag set:


#5

To follow up on this, I submitted a PR and it got reviewed, so it should hopefully land soon. It will need to be stabilized before it reaches stable, but I don’t think that will be difficult. It adds a std::os::windows::process::CommandExt trait with a creation_flags method, so you will be able to use that trait and then call creation_flags(DETACHED_PROCESS) on a std::process::Command.

The test I wrote for the feature shows an example, it’s using the Windows Debugger API to implement a minimal debugger!