Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breaking away a process started from C#

I have some existing code making use of System.Diagnostics.Process.Start to start a child process. It also uses ProcessStartInfo.RedirectStandardOutput to capture the output stream of that process. This much is working fine.

I also need to attach it to a job object. I have code which does this as well, and it works fine provided that the process is not already attached to a job.

Unfortunately, that isn't always the case, so I need to create the process with the CREATE_BREAKAWAY_FROM_JOB flag. This is where I'm stuck.

As I see it, there are two possible ways forward from here:

  1. Somehow convince Process.Start to pass that one extra little flag.
  2. Abandon the Process class, fall back to raw CreateProcess, and (somehow) redo the output redirection.

I'm not really sure how to do either of these, or if there's some middle ground which might also work. Has anyone else run into this before and have some ideas/code?

like image 711
Miral Avatar asked Nov 13 '22 12:11

Miral


1 Answers

For the moment, I've gone with option #2. I think I've worked out how to do the output capturing, though I haven't tested it extensively yet.

Still interested in alternative ideas, though.

like image 176
Miral Avatar answered Nov 16 '22 03:11

Miral