1

I have a console application which does a set of operations and gives out messages after completion of each operation. When I run my console app, the messages in my console window may look like this:

Checking prerequisites...
Completing prerequisites..
Performing installation...
Completing installation...
Done..!

Now I'm executing this console application from one of my C# windows applications by using Process.StartInfo(). I need to get all the messages thrown by my console application to be displayed in the windows form of my application.

Can this be done?

Thanks.

Sandeep
  • 5,581
  • 10
  • 42
  • 62
  • possible duplicate of [Capturing the Console Output in .NET (C#)](http://stackoverflow.com/questions/186822/capturing-the-console-output-in-net-c) – RvdK Jul 11 '11 at 12:39

2 Answers2

4

Look here Capturing console output from a .NET application (C#)

Community
  • 1
  • 1
Andy
  • 429
  • 3
  • 9
1

This can be quite easily achieved using the ProcessStartInfo.RedirectStandardOutput Property. A full sample is contained in the linked MSDN documentation.

Process compiler = new Process();
compiler.StartInfo.FileName = "csc.exe";
compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();    

Console.WriteLine(compiler.StandardOutput.ReadToEnd());

compiler.WaitForExit();
Bibhu
  • 4,053
  • 4
  • 33
  • 63