【发布时间】:2022-03-10 00:54:16
【问题描述】:
我想在 C# 中读取 cmd 的连续输出流。我知道我可以重定向标准输出流并读取它。以下是代码:
System.Diagnostics.ProcessStartInfo pi= new System.Diagnostics.ProcessStartInfo(ProgramPATH,Params);
pi.RedirectStandardOutput = true;
pi.UseShellExecute = false;
pi.CreateNoWindow = true;
System.Diagnostics.Process proc= new System.Diagnostics.Process();
proc.StartInfo = pi;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
但这一次给出了整个输出。如果我发出带有-t 参数的ping 命令怎么办?我怎样才能不断地阅读这个流?
【问题讨论】: