我想要 .RedirectStandardOutput = true/false

发布于 2024-09-17 01:32:54 字数 818 浏览 0 评论 0原文

//通过这段代码,我希望将要执行的批处理文件将在外壳屏幕上显示我通过 RedirectStandardOutput = false; 获得的输出

,但我也希望同时输出应该被重定向为此我必须将其写入日志文件 RedirectStandardOutput = true;

但一旦可以使用 truefalse 请帮助我伟大的程序员...!!

        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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么这么可爱啊 2024-09-24 01:32:57

您可以将从 p.StandardOutput 收到的输出写入 Console.Write
要查看实时显示的输出,请将单个 ReadToEnd 调用替换为对 ReadLine 的循环调用。

You can write the output that you received from p.StandardOutput to Console.Write.
To see the output appear in real time, replace the single ReadToEnd call with a looped call to ReadLine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文