@
sarlanori 试了以下代码,但是 richtextbox 控件中还是只能等 py 文件运行完才一次性显示所有的 print 输出,不知道怎么改。。。。
##
aaa.py 每隔 2 秒打印一个值
import time
for i in range(0,5):
print i
time.sleep(2)
## c#代码段
using (Process process = new System.Diagnostics.Process())
{
process.StartInfo.FileName = "python";
process.StartInfo.Arguments = "
aaa.py";
// 必须禁用操作系统外壳程序
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
// 异步获取命令行内容
process.BeginOutputReadLine();
process.BeginErrorReadLine();
// 为异步获取订阅事件
process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);
process.ErrorDataReceived += new DataReceivedEventHandler(process_ErrorDataReceived);
}