Disabling a process started with C #

I have some existing code using System.Diagnostics.Process.Start to start a child process. It also uses ProcessStartInfo.RedirectStandardOutput to capture the output of this process. It works very well.

I also need to attach it to the object. I have a code that does this too, and it works fine provided that the process is not attached to the task yet.

Unfortunately, this is not always the case, so I need to create a process with the flag CREATE_BREAKAWAY_FROM_JOB . This is where I am stuck.

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

  • Somehow convincing Process.Start to pass this extra small flag.
  • Cancel the Process class, go back to raw CreateProcess and (somehow) repeat the output redirection.

I am not sure how to do this, or if there is some kind of medium soil that can also work. Has anyone else come across this before and have some ideas / code?

+4
source share
1 answer

At the moment I went with option number 2. I think I developed how to draw a capture output, although I have not tested it yet.

Still interested in alternative ideas.

+1
source

Source: https://habr.com/ru/post/1386656/


All Articles