Pipe a stream to Debug.Write()

二次信任 提交于 2020-01-04 04:31:05

问题


I am running a command line utility using Process.Start. For debugging purposes I would like to have its output stream to Visual Studio's Debug Output panel (Debug.Write). I'd like to do this in real time rather than waiting for the process to complete and then writting it all at once.

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


回答1:


This may not be exactly what you want, but it puts you on the right track, I think.

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

Then, your event handler for receiving data.

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


来源:https://stackoverflow.com/questions/17370705/pipe-a-stream-to-debug-write

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!