【发布时间】:2014-09-17 09:39:22
【问题描述】:
我正在编写一个读取 python 脚本输出并在文本框中显示结果的程序。 由于脚本运行了很长时间,我希望能够每 1 秒(或每行写入后)看到输出。 现在我只能在进程结束时看到输出。 有人知道是什么问题吗?
我的代码的sn-p:
Process p = new Process();
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.OutputDataReceived += new DataReceivedEventHandler (p_OutputDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler (p_ErrorDataReceived);
p.Exited += new EventHandler (p_Exited);
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "python.exe";
p.StartInfo.Arguments = "path " + commandline;
p.Start();
StreamReader s = p.StandardOutput;
String output = s.ReadToEnd();
textBox3.Text = output;
p.WaitForExit();
【问题讨论】: