8
我想逐行檢查過程的標準輸出。讀取第二行myProcess.StandardOutput.EndofStream後,從false更改爲true。因此它從while循環退出。也許我應該使用別的東西?如何逐行讀取標準輸出?
Process myProcess = new Process();
try
{
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = my_command;
myProcess.StartInfo.Arguments = " "+ location;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.Start();
while (!myProcess.StandardOutput.EndOfStream)
{
string standard_output = myProcess.StandardOutput.ReadLine();
if (standard_output.Contains("xx"))
{
//do something
break;
}
}
myProcess.WaitForExit();
}