我的目标是读取过程提供的输出并搜索特定的字符串。可悲的是,我的程序在读取输出的第四行(我输入查询的位置)时会自行挂起。最有可能与此有关。但是我不明白如何。
这是我的输出:
https://www.bilder-upload.eu/bild-76fdfa-1558432298.png.html
try
{
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.Arguments = query;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.Start();
while (cmd.StandardOutput.EndOfStream == false || !cmd.HasExited)
{
string line = cmd.StandardOutput.ReadLine();
if(line.Contains("STATE : 4 RUNNING "))
{
Console.WriteLine("IS RUNNING");
}
}
cmd.WaitForExit();
cmd.Dispose();
}
catch (Exception ex)
{
logger.Debug(ex, "Execution failed");
}