问题描述
|
我正在使用Process类调用控制台应用程序。我将输出重定向到日志文件,但是当我不重定向输出时,控制台窗口中的消息多于我时不在日志文件中的消息。有什么想法吗?
ProcessStartInfo psi = new ProcessStartInfo();
string filename = @\"ProgrammingMaster_LocalPowertrain.exe\";
psi.FileName = filename;
string arguments = String.Format(\"{0} {1} false\",InstanceId.ToString(),ManifestFolderPath);
psi.Arguments = arguments;
LogMessage(msgType.Warning,filename + \" - \" + arguments);
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
FBlockProcess = new Process();
FBlockProcess.StartInfo = psi;
FBlockProcess.OutputDataReceived += new DataReceivedEventHandler(FBlockProcess_OutputDataReceived);
FBlockProcess.ErrorDataReceived += new DataReceivedEventHandler(FBlockProcess_ErrorDataReceived);
FBlockProcess.Start();
FBlockProcess.BeginOutputReadLine();
FBlockProcess.BeginErrorReadLine();
在我的OutputDataReceived处理程序中,我只是将字符串添加到ConcurrentQueue
编辑:
我应该补充一点,我想实时或接近捕获输出。该过程可能要花费30多分钟才能运行,我不想等那么久才能看到正在发生的事情。
更新:
输出前四行后,就永远不会调用OutputDataReceived eventHandler,即使我知道当我不进行重定向时,还会有10或15行输出到控制台。有什么想法可能导致这种情况吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)