I am developing a Windows Forms application that requires me to invoke a separate program to complete a task. The program is a console application, and I need to redirect standard output from the console to the TextBox in my program.
I have no problem running the program from my application, but I donβt know how to redirect the output to my application. I need to capture the output while the program is running using events.
The console program is not intended to stop until my application stops and the text changes randomly. What I'm trying to do is simply pull the console out of the console to call the event handler, which can then be used to update the TextBox.
I use C # to code the program and use the .NET platform for development. The source application is not a .NET program.
EDIT: Here is a sample code of what I'm trying to do. In my last application, I replaced Console.WriteLine with code to update the TextBox. I tried to set a breakpoint in the event handler, and this has not even been achieved.
void Method() { var p = new Process(); var path = @"C:\ConsoleApp.exe"; p.StartInfo.FileName = path; p.StartInfo.UseShellExecute = false; p.OutputDataReceived += p_OutputDataReceived; p.Start(); } static void p_OutputDataReceived(object sender, DataReceivedEventArgs e) { Console.WriteLine(">>> {0}", e.Data); }
Null Jan 6 '09 at 6:20 2009-01-06 06:20
source share