title: Start a process using System.Diagnostics.Process.Start
body: <p>I am trying to execute a file stored under program files. The program is usually called from a command prompt, and output information while it is running. I want to capture the output.</p>
  
  <p>The code below solves half of the job: The program is executed, and the console pops up showing the output in the console, but I cannot capture the output:</p>
  
  <pre><code>ProcessStartInfo start = new ProcessStartInfo();
  start.WorkingDirectory = directory;
  start.FileName = fileName;
  start.Arguments = arguments;
  //start.UseShellExecute = false;
  //start.RedirectStandardOutput = true;
  
  using (Process process = Process.Start(start))
  {
     // code
  }
  </code></pre>
  
  <p>Now I am using the code below to capture the output:</p>
  
  <pre><code>ProcessStartInfo start = new ProcessStartInfo();
  start.WorkingDirectory = directory;
  start.FileName = fileName;
  start.Arguments = arguments;
  start.UseShellExecute = false;
  start.RedirectStandardOutput = true;
  
  using (Process process = Process.Start(start))
  {
     using (StreamReader reader = process.StandardOutput)
     {
        string result = reader.ReadToEnd();
        Console.Write(result);
     }
  }
  </code></pre>
  
  <p>The program crashes in the line where I execute the start command with the error "The system cannot find the file specified"</p>
  
  <p>What I don't get is, the first part of the program works, but not the second.</p>
  
  <p>I have search a lot on this topic, and there are many suggestions but have not been able to find one which solves my issue.</p>
  
  <p>I am using .NET 3.5 for the program which I prefers due to compatibility with other parts of the program.</p>