title: How to redirect standard output when spawning a process
body: <p>I've built a webservice for an internal server that I want to send a command to and have it launch a process. So I want to send a command to it like this:</p>
  
  <pre><code>http://machine:999/execute?path=c:\scripts\dostuff.exe&amp;args=-test
  </code></pre>
  
  <p>The endpoint would then do something like this:</p>
  
  <pre><code>public ActionResult(string path, string args)
  {
  
      var proc = new System.Diagnostics.Process();
      proc.StartInfo.FileName = path;
      proc.StartInfo.Arguments = args;
      proc.StartInfo.UseShellExecute = false;
      proc.StartInfo.CreateNoWindow = true;
      proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
      proc.StartInfo.RedirectStandardOutput = true;
  
      //Hook into all standard output here
  
      //Block until process is returned - Async Controller action
  
      return Content(output.ToString())
  }
  </code></pre>
  
  <p>I want to be able to capture all the error messages and standard output generated by the executable. The executable could be anything like a console application or a powershell script. What's the best approach for doing something like this?</p>