-3

I kick off a Console application from my process. It does a task, writes a bunch of stuff to the console, then terminates.

Given that I've kicked off the Console app, is it possible for me to intercept what is being written to the console?

Note that there is a similar question, but it's for c++ and I am not sure how to translate the semantics. I've asked a similar question in the past, but it's for my own process only.

Community
  • 1
  • 1
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
  • 1
    Yes, and it's done all the time and there are lots of examples of this all over the net. Just spend some time looking through the `Process` class's documentation on MSDN, it has lots of good examples. – Servy Feb 06 '13 at 19:29

1 Answers1

1
Process process = new Process();
process.OutputDataReceived += LogOutput;

You can create a method and place it in the OutputDataReceived event before starting the process.

private static void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
    ...
}
Amaranth
  • 2,433
  • 6
  • 36
  • 58
  • 1
    There's actually a bit more to it than this; you need to set a number of properties appropriately for the `StartInfo` of the `Process` class. It's easier to just look at the examples on MSDN though; in this particular case they're quite good. – Servy Feb 06 '13 at 19:37