After the link suggested by David, I decided to write a solution to your problem that is more specific to your case. This version allows you to get standard output in your GUI using the BackgroundWorker PropertyChangedEventHandler callback.
Here is the code for ConsoleRedirector:
public class ConsoleRedirector : IDisposable { private static ConsoleRedirector _instance; public static void attach(ProgressChangedEventHandler handler, bool forceConsoleRedirection) { Debug.Assert(null == _instance); _instance = new ConsoleRedirector(handler, forceConsoleRedirection); } public static void detatch() { _instance.Dispose(); _instance = null; } public static bool isAttached { get { return null != _instance; } } private static void ResetConsoleOutStream() {
Here's a link to the full sample form, which demonstrates how to use it: ConsoleRedirector console form example
source share