views:

16

answers:

1

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

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.

SLaks
but this is my windows form application how can i use console.writei got an output when i am using p.StartInfo.RedirectStandardOutput = false; but if i use "false" i am unable to redirect the output in a log file... i want both plz give me solution :(