问题描述
目前,我开始从我的C#程序用一个批处理文件:
System.Diagnostics.Process.Start(@DoSomeStuff.bat);
我想能够做的是,子进程的输出(stdout和stderr)重定向到Visual Studio中的输出窗口(具体的Visual C#防爆preSS 2008)。
有没有办法做到这一点?
(另外:这样,它不是所有缓冲了再吐出来,当子进程结束Output窗口)
(BTW:现在我可以得到标准输出(而不是标准错误)的的父的过程出现在输出窗口,通过我的节目一个Windows应用程序,而不是控制台应用程序。这打破,如果该程序的Visual Studio之外运行,但这是我的具体情况确定。)
process.StartInfo.CreateNoWindow = TRUE;
process.StartInfo.UseShellExecute = FALSE;
process.StartInfo.RedirectStandardOutput =真;
process.OutputDataReceived + =(发件人,参数)=> Console.WriteLine(args.Data);
process.BeginOutputReadLine();
为错误
同样的想法,只需更换输出
这些方法/属性名。
At the moment I am starting a batch file from my C# program with:
System.Diagnostics.Process.Start(@"DoSomeStuff.bat");
What I would like to be able to do is redirect the output (stdout and stderr) of that child process to the Output window in Visual Studio (specifically Visual C# Express 2008).
Is there a way to do that?
(Additionally: such that it's not all buffered up and then spat out to the Output window when the child process finishes.)
(BTW: At the moment I can get stdout (but not stderr) of the parent process to appear in the Output window, by making my program a "Windows Application" instead of a "Console Application". This breaks if the program is run outside Visual Studio, but this is ok in my particular case.)
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data);
process.BeginOutputReadLine();
Same idea for Error
, just replace Output
in those method/property names.
这篇关于重定向子进程的输出(stdout,标准错误)在Visual Studio Output窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!