Thanks to this post, 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
def test():
raise Exception
my C# 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();
}
can not read the error message by string stderr = p.StandardError.ReadToEnd(); In fact itself threw an exception "An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll"
How can I solve this?
InvalidOperationException?