Redirect console output to textbox in separate program Capturing nslookup shell output with C#
I am looking to call an external program from within my c# code.
The program I am calling, lets say foo.exe returns about 12 lines of text.
I want to call the program and parse thru the output.
What is the most optimal way to do this ?
Code snippet also appreciated :)
Thank You very much.
using System;
using System.Diagnostics;
public class RedirectingProcessOutput
{
public static void Main()
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c dir *.cs";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine("Output:");
Console.WriteLine(output);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With