开发者

I want both .RedirectStandardOutput = true/false

开发者 https://www.devze.com 2023-01-13 10:56 出处:网络
//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;

//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);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消