它不起作用的原因是因为你有UseShellExecute = false
。
如果不使用外壳程序,则必须以方式提供python可执行文件的完整路径FileName,并构建Arguments
字符串以提供脚本和要读取的文件。
另请注意,RedirectStandardOutput
除非你不能这样做UseShellExecute = false
。
我不太确定应如何为python格式化参数字符串,但你将需要以下内容:
private void run_cmd(string cmd, string args)
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = "my/full/path/to/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);
}
}
}