I am trying to invoke the following .py script: (python version installed: 3.11.4)
TaskName= input("Kindly Enter which task should be executed, for Eg: A1,B1,C1 : ")
print(TaskName)
from the below simple C# code:
string path = @"C:\Program Files\Python311\python.exe";
string input = @"C:\app\new_7.py";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = path;
startInfo.Arguments = "\"" + input + "\"";
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
using (Process exeProcess = Process.Start(startInfo))
{
string line = exeProcess.StandardOutput.ReadToEnd();
exeProcess.WaitForExit();
if (exeProcess.ExitCode == 0) MessageBox.Show("External program is executed successfully.");
else MessageBox.Show("External program execution was not successful.");
line = string.IsNullOrEmpty(line) ? line : line.TrimEnd(new char[] { '\r', '\n' });
MessageBox.Show(line);
}
But, it doesn't show-up the prompt what i see when i run the script by double clicking the .py (screenshot below). When debugged, i see this code: using (Process exeProcess = Process.Start(startInfo)) passes without showing the prompt and gets stuck at next line: string line = exeProcess.StandardOutput.ReadToEnd();
Can anyone give some hint on where i am going wrong?
I don't want new window that's why : startInfo.CreateNoWindow = true;.
If i set it to False: it flashes the prompt and goes immediately.
I have seen the similar issue asked in this: Run Python script in c# does nothing
But the solution doesn't work for me.
