I want to run a console application that will output a file.
I user the following code:
Process barProcess = Process.Start(\"bar.exe\", @\"C:\\foo.txt\")
If you would like to retrieve the output of the process while it is executing, you can do the following (example uses the 'ping' command):
var info = new ProcessStartInfo("ping", "stackoverflow.com") {
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
};
var cmd = new Process() { StartInfo = info };
cmd.Start();
var so = cmd.StandardOutput;
while(!so.EndOfStream) {
var c = ((char)so.Read()); // or so.ReadLine(), etc
Console.Write(c); // or whatever you want
}
...
cmd.Dispose(); // Don't forget, or else wrap in a using statement