title: Catch Exception when calling python from C#
body: <p>Thanks to this <a href="http://How%20do%20I%20run%20a%20Python%20script%20from%20C#?" rel="nofollow noreferrer">post</a>, I managed to call python script from C#, however, I am not able to detect if the python code threw an exception. For example given a python script</p>
  
  <pre><code>def test():
      raise Exception
  </code></pre>
  
  <p>my C# code </p>
  
  <pre><code>Process p = new Process();
  p.StartInfo = new ProcessStartInfo(cmd, args)
  {
      RedirectStandardOutput = true,
      UseShellExecute = false,
      CreateNoWindow = true
  };
  p.Start();
  
  using (StreamReader reader = p.StandardOutput)
  {
      string stderr = p.StandardError.ReadToEnd();
      string result = reader.ReadToEnd(); 
  }
  </code></pre>
  
  <p>can not read the error message by <code>string stderr = p.StandardError.ReadToEnd();</code> In fact itself threw an exception <code>"An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll"</code></p>
  
  <p>How can I solve this?</p>