I am new to C# and I tried to execute a python program using the ProcessStartInfo class. I followed this link and did the same. However, I cannot get any redirect output. I tried to execute the Python interpreter with the argument and there were no problems. However, I saw the console pop up and then went away immediately. There was no output print. I tried to use the method process.waitForExit() but the console also went away. Any ideas?
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\python.exe";
start.Arguments = @"C:\Users\test\test.py";
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
start.RedirectStandardError = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
process.WaitForExit();
}
}