Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在通过Process.Start(). 我尝试重定向输出以获取行。
Process.Start()
但是,现在,我只需要最后一行。
有没有办法只阅读最后一行,还是我还需要全部redirectStandaroutput = false;等?
redirectStandaroutput = false;
有没有更简单的方法?
如果我必须通过process.Redirect(),我尝试按照 MSDN 和其他outputdatareceived事件源上的示例进行操作,但我的输出仅在最后写入控制台并且不是异步的。
process.Redirect()
outputdatareceived
一旦您使用process.Start()我知道的唯一读取输出的方法就是使用.RedirectStandardInput = true;. 由于标准输出是一个流对象,最后一行只能通过读取整个流来读取。
process.Start()
.RedirectStandardInput = true;
顺便说一句proc.StandardOutput.ReadToEnd(),您的线程将挂起,直到进程退出,如果您在阅读过程中收到任何提示 - 您的应用程序将挂起。
proc.StandardOutput.ReadToEnd()