Wie Lesen von standard-Ausgabe-Zeile für Zeile?

Möchte ich untersuchen Zeile für Zeile von der standard-Ausgabe aus dem Prozess. nach dem Lesen der zweiten Zeile myProcess.StandardOutput.EndofStream ändern von false auf true. Daher verlässt while-Schleife. Vielleicht sollte ich etwas anderes verwenden?

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();
}
InformationsquelleAutor John Ryann | 2014-01-09
Schreibe einen Kommentar