Pull the stream in Debug.Write ()

I am running a command line utility using Process.Start . For debugging purposes, I would like to have my output stream in the Visual Studio Debug Output panel ( Debug.Write ). I would like to do this in real time, and not wait for the process to complete and then expose all of this.

I know that this is possible in theory, but I'm not experienced with the Stream object to know how to do this.

+2
source share
1 answer

It may not be exactly what you want, but, in my opinion, it leads you on the right path.

 p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.OutputDataReceived += p_OutputDataReceived; p.Start(); p.BeginOutputReadLine(); 

Then your event handler to retrieve the data.

 void p_OutputDataReceived(object sender, DataReceivedEventArgs e) { Debug.Write(e.Data); } 
+3
source

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


All Articles