管流至Debug.Write() [英] Pipe a stream to Debug.Write()

查看:143
本文介绍了管流至Debug.Write()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Process.Start 运行一个命令行工具。出于调试目的,我想有它的输出流到Visual Studio的调试输出面板( Debug.Write )。我想这样做实时,而不是等待的过程中完成,然后书面方式一次全部。

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.

推荐答案

这可能不是正是你想要的,但它让你在正确的轨道,我想。

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);
}

这篇关于管流至Debug.Write()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆