0

Is it possible to get the console output of a running process? I know I can get a list of all running processes like this:

Process.GetProcesses();

But how can I tap into the standard output and pipe it to a file or to a different console app.

The presuppose is to create a debugging\ tracing tool to an existing application that I cannot change. The app fires a specific process and does not set the RedirectStandardOutput property so I have no way of diganosting the output of that child process.

Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44
Mortalus
  • 10,574
  • 11
  • 67
  • 117

1 Answers1

0

What you're asking for isn't really possible in C#. If you drop down a layer to native C++, it's possible (though still relatively difficult) to accomplish this by using the Windows API to implement API Hooking as described in this answer.

Before going down this road, pay attention to the rest of the discussion in that answer. The vast majority of the time, this isn't want you want to do. As mentioned in that discussion, a program owns its own stdout and you don't change carpets in someone else's house. Also anticipate what should happen if two programs try to do this at once.

Community
  • 1
  • 1
Tim Copenhaver
  • 3,282
  • 13
  • 18