Skip to main content
 首页 » 编程设计

c#之使用 System.Diagnostic Process 时,我会错过进程开始和捕获输出开始之间的一些输出行吗

2024年02月24日24hnrainll

如果我有这样的代码

proc.Start(); 
string resultOut; 
 
while ( (!proc.HasExited && (resultOut = stdOut.ReadLine()) != null)) 
{ 
// Do some operation based on resultOut 
} 

从开始处理到捕获/解析开始,我是否容易错过某些行,还是会等待?如果没有,我该怎么办?

请您参考如下方法:

如果您通过 ProcessStartInfo.RedirectStandardOutput 重定向进程的输入和/或输出等,流程输出将直接进入您的流。您不会错过任何输入或输出。