我正在尝试使用process.BeginOutputReadLine()
从c#执行Python我的问题是python的接收结果只显示python prog完成后并没有真正执行readline 这是我的代码
public void ExecuteProcess()
{
using (var process = new Process())
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.FileName = "python.exe";
process.StartInfo.Arguments = string.Format("{0} ", @"C:\FB\mytestpython.py");
process.OutputDataReceived += (sender, args) =>
{
if (args.Data != null)
{
//write data
UpdatePythonLog(args.Data);
}
};
process.Start();
process.BeginOutputReadLine();
}
return ;
}
这是我的Python代码:
import time
if __name__=='__main__':
print "test1"
time.sleep(5)
print "test2"
time.sleep(5)
print "test3"
time.sleep(5)
print 'finish'