我想同时.RedirectStandardOutput = true/false
问题描述:
//通过此代码我希望将要执行的批处理文件将显示shell屏幕上的输出,我得到RedirectStandardOutput = false;我想同时.RedirectStandardOutput = true/false
但我也希望在同一时间输出应该重定向到一个日志文件为此我必须这样做RedirectStandardOutput = true;
但一旦一个可以使用,也可以真正或假请帮我很大的编程人员...!
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);
答
你可以写你收到p.StandardOutput
到Console.Write
输出。
要查看输出实时显示,请将单个ReadToEnd
呼叫替换为ReadLine
的循环呼叫。
+0
但这是我的Windows窗体应用程序如何使用console.write 我得到了一个输出,当我使用p.StartInfo.RedirectStandardOutput = false;但如果我使用“假”我无法重定向输出在日志文件中...我希望两个PLZ给我解决方案:( – user434934 2010-08-31 04:31:44
这是哪一种语言? C#?请用适当的语言标签标记它。 – 2010-08-30 12:33:03
请勿标记您的帖子,因为您需要帮助。它滥用了调节系统。 – Will 2010-08-31 10:10:32