我想要 .RedirectStandardOutput = true/false
//通过这段代码,我希望将要执行的批处理文件将在外壳屏幕上显示我通过 RedirectStandardOutput = false; 获得的输出
,但我也希望同时输出应该被重定向为此我必须将其写入日志文件 RedirectStandardOutput = true;
但一旦可以使用 true 或 false 请帮助我伟大的程序员...!!
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "c:\test\build.bat";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = null;
// try
// {
output = p.StandardOutput.ReadToEnd();
// }
// catch (Exception ex)
// {
// MessageBox.Show(ex.ToString());
// }
System.IO.File.WriteAllText("c:\test\log.txt", output);
//by this code i want the batch file which is going to be executed will show the output on shell screen which i got by RedirectStandardOutput = false;
but i also want at that same time output should be redirected to a log file for this i have to do this as RedirectStandardOutput = true;
but once one can be used either true or false please help me great programers ... !!
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "c:\test\build.bat";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = null;
// try
// {
output = p.StandardOutput.ReadToEnd();
// }
// catch (Exception ex)
// {
// MessageBox.Show(ex.ToString());
// }
System.IO.File.WriteAllText("c:\test\log.txt", output);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将从
p.StandardOutput
收到的输出写入Console.Write
。要查看实时显示的输出,请将单个
ReadToEnd
调用替换为对ReadLine
的循环调用。You can write the output that you received from
p.StandardOutput
toConsole.Write
.To see the output appear in real time, replace the single
ReadToEnd
call with a looped call toReadLine
.