Muss der Output von Konsolanwendungen direkt geparsed werden, kann das via Streamreader und der Standardoutput-Eigenschaft von System.Diagnostics.Process auf direktem Wege getan werden.
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
try
{String aufruf, parameter;
aufruf = „c:\\windows\\system32\\netstat.EXE“;
parameter = „-na“;
Console.WriteLine(aufruf + “ “ + parameter);
myProcess.StartInfo.Arguments = parameter;
myProcess.StartInfo.FileName = aufruf;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true; //<– Das hier sorgt dafuer, das stdout direkt zugreifbar wird
myProcess.Start();
myProcess.WaitForExit();
Console.WriteLine(„Ergebnis des netstats: {0}“, myProcess.ExitCode);}
catch (Exception e)
{
Console.WriteLine(„Fehler beim NETSTAT“);
Console.WriteLine(e.Message);
}try
{
using (StreamReader sr = myProcess.StandardOutput)
{
String line;
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
catch (Exception e)
{
Console.WriteLine(„Fehler beim Auslesen des Outputs“);
Console.WriteLine(e.Message);
}
Für Standarderror und Standardinput funktioniert das natürlich auch