I have a GUI application that I'm writing in C#, and I need to run a Python script when a button is clicked. The Python script is exiting due to an error, and the window that appears closes immediately so I'm unable to see where the error is happening. Is there any way to prevent the window from closing?
I've seen some other suggestions such as using WaitForExit(), but that still hasn't worked. I've found some answers that have provided suggestions for running a command prompt from C#. This is what I'm currently trying:
private void buttonClick(object sender, EventArgs e)
{
var p = new System.Diagnostics.Process();
p.StartInfo.FileName = "python.exe";
p.StartInfo.Arguments = "C:\\Path\\To\\Python\\Main.py";
p.Start();
p.WaitForExit();
}
I'd expect p.WaitForExit() to prevent the python window from closing, but clearly the error within the python program is forcing it closed.