I'm writing a WCF service which runs python scripts.
For That I've been using the following code:
ProcessStartInfo start = new ProccessStartInfo();
start.FileName = "my/full/path/to/python.exe";
start.Arguments = string.Format("{0} {1}", script, args);
start.UseShellExecute = false;
start.CreateNoWindow = true;
start.RedirectStandardOutput = true;
start.RedirectStandardError = true;
Process p = new Process();
p.StartInfo = start;
p.Start();
p.WaitForExit();
string stderr = Process.StandardError.ReadToEnd();
string stdout = Process.StandardOutput.ReadToEnd();
Now what I've noticed (After a lot of testing) is that the Process object gets the Standard Error/Output or catches an exception if the error is related to "Compilation" errors, like if I have an undeclared variable used or stuff like that, but runtime exceptions and prints are not being caught or able to be read in the C# scope.
I've tried to run either the whole "python.exe pythonCommand.py args" as they are sent from the C# code or just send what was in the ProcessStartInfo.Arguments in the Command Line Prompt and it returned exceptions and prints in both cases, but still when I run it via the C# Process object I get no exceptions thrown at me to catch and no output or error what so ever.
I've found nothing about this which makes me feel kind of stupid (hopefully I am and this has a simple solution), and I would really appreciate if someone that has stumbled upon this case could help me out.
Thanks, Matt