Skip to content

Instantly share code, notes, and snippets.

@runesoerensen
Created June 26, 2013 17:51
Show Gist options
  • Save runesoerensen/5869669 to your computer and use it in GitHub Desktop.
Save runesoerensen/5869669 to your computer and use it in GitHub Desktop.
Sample console app that redirects stdout and stderr from another process to the current error and output streams
public class Program
{
public static void Main(string[] args)
{
var processStartInfo = new ProcessStartInfo
{
FileName = "C:\\foo.exe",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
};
using (var process = Process.Start(processStartInfo))
{
process.OutputDataReceived += (sender, output) =>
{
Console.WriteLine(output.Data);
};
process.ErrorDataReceived += (sender, output) =>
{
Console.Error.WriteLine(output.Data);
};
process.BeginOutputReadLine();
process.WaitForExit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment