我在WPF的C文件中运行了一个Python进程:
ProcessStartInfo StartInfo = new ProcessStartInfo(@"python ", location);
StartInfo.UseShellExecute = false;
StartInfo.CreateNoWindow = true;
StartInfo.RedirectStandardOutput = true;
StartInfo.RedirectStandardError = true;
try
{
p.StartInfo = StartInfo;
p.EnableRaisingEvents = true;
p.OutputDataReceived += new DataReceivedEventHandler(OnDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(OnDataReceived);
p.Exited += new EventHandler(OnProcessExit);
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
}
catch (Exception exc)
{
Console.Write(exc);
}
后来:
private void OnDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
torOut = e.Data;
Console.WriteLine(torOut);
}
}
我的Python程序每秒打印多条消息。当我运行这个命令时,只会出现一些输出;例如,print "message"
可能会被调用50次,只有在第50次之后,所有50条消息才会作为一个批出现。你知道吗
我的方法是否有问题,或者标准输出的读取速度是否特别慢/断断续续?你知道吗
万一有人有类似的问题,我最终还是解决了。在需要任何时间输出后添加以下内容:
相关问题 更多 >
编程相关推荐