Created
June 26, 2013 17:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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