Below is a call to a Python process but it doesn't return the StandardOutput
. I intently made a typo inside the Python file and it successfully returned the StandardError
.
string pythonExe = @"../../../Vokaturi/python.exe";
string pythonFile = @"../../../Vokaturi/test.py";
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(pythonExe);
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.RedirectStandardError = true;
myProcessStartInfo.Arguments = pythonFile;
Process myProcess = new Process();
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
StreamReader myStreamReaderError = myProcess.StandardError;
string myErrorString = myStreamReaderError.ReadToEnd();
StreamReader myStreamReaderOutput = myProcess.StandardError;
string myOutputString = myStreamReaderOutput.ReadToEnd();
myProcess.WaitForExit();
myProcess.Close();
That means the way I call the files in their paths are correct. I also tried it in command prompt and it returns the necessary output without error. When I debug the code, it says it threw an exception of type system.invalidoperationexception
(after myProcess.start()
).
But it says here that it's expected. What am I missing? Thank you in advance for your guidance.