I'm making a mini Python IDE for fun. Why not. So I want to be able to call a python script from C# and right now I'm just testing a simple scenario. I know this is NOT how professional IDE's probably work.
private void Run_Click(object sender, EventArgs e)
{
run_cmd("C:/Python34/python.exe", "C:/Users/Alaseel/Desktop/test.py");
}
private void About_Click(object sender, EventArgs e)
{
// Open the about documentation
}
private void run_cmd(string cmd, string args)
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = "C:/Python34/python.exe";
start.Arguments = string.Format("{0} {1}", cmd, args);
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
}
}
}
Whenever I click the "run" button on the Windows Form app, it briefly runs the python.exe then closes. It does not actually run the file that I passed in. Am I doing something wrong?
PS: The run_cmd method is NOT mine. I looked up this issue previously on a thread and used their code. But I think I'm using the method wrong.
Any ideas? Thank you!