相关疑难解决方法(0)

将子进程的输出(stdout,stderr)重定向到Visual Studio中的"输出"窗口

目前我正从我的C#程序启动批处理文件:

System.Diagnostics.Process.Start(@"DoSomeStuff.bat");
Run Code Online (Sandbox Code Playgroud)

我希望能够做的是将该子进程的输出(stdout和stderr)重定向到Visual Studio中的Output窗口(特别是Visual C#Express 2008).

有没有办法做到这一点?

(另外:这样就不会全部缓冲,然后在子进程完成时吐出到Output窗口.)


(顺便说一句:目前我可以通过使我的程序成为"Windows应用程序"而不是"控制台应用程序"来使进程的stdout(但不是stderr)出现在"输出"窗口中.如果程序运行,这会中断在Visual Studio之外,但在我的特定情况下这是好的.)

c# stdout visual-studio-2008 visual-studio output-window

14
推荐指数
2
解决办法
2万
查看次数

C#处理标准输出延迟

从 C# 表单中,我正在运行一个进程,其启动信息类似于将控制台输出重定向到单独程序中的文本框,并且C# 在运行时获取进程输出,该进程运行正确,但输出需要很长时间才能出现在DataReceived 事件中。

我希望在流程生成后立即看到文本;根据流程标准输出无法捕获?(第一条评论)我需要等到 2 到 4 kb 的缓冲区填满后才能触发事件。

根据要求,这是代码:

void pcs_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
    if (!string.IsNullOrEmpty(e.Data)) 
        textBox1.BeginInvoke((Action)delegate { textBox1.AppendText(text + "\n"); });
}

private void LER_Go_Click(object sender, EventArgs e)
{
    // variables LiDARExtRep contains the full path to an executable file
    // that runs in DOS and produces verbose output.
    // LER_Path.Text is the parameter passed to LiDARExtRep (only one arg for this example)
    ProcessStartInfo pStartInfo …
Run Code Online (Sandbox Code Playgroud)

c# forms buffer stdout process

1
推荐指数
1
解决办法
1929
查看次数