我正在制作一个迷你Python IDE来好玩。为什么不。所以我希望能够从C调用一个python脚本,现在我只测试一个简单的场景。我知道这不是专业IDE的工作原理。在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);
}
}
}
每当我单击Windows窗体应用程序上的“运行”按钮时,它都会短暂地运行python.exe然后关闭。它实际上并不运行我传入的文件。我做错什么了吗?在
注:run_cmd方法不是我的。我以前在一个线程上查过这个问题,并使用了他们的代码。但我觉得我用错了方法。在
有什么想法吗?谢谢您!在