Capturing output from an unrelated process

I'm just wondering if it's possible to capture the output of a separate process running on windows?

For example, if I have a console application running, can I launch a second application, a forms application, and make this application capture output from the console application and display it in a text box?

+3
source share
3 answers

You can do it:

    Process[] p = Process.GetProcessesByName("myprocess.exe");

    StreamReader sr = p[0].StandardOutput;

    while (sr.BaseStream.CanRead)
    {
        Console.WriteLine(sr.ReadLine());
    }
0
source

You can redirect stdout / stderr (standard thread / error stream) of the process if you run it. As an example, consider this .

Capturing the output stream of a process that was not started by you, well, that’s a completely different matter. I am not sure that this can be done.

, , pipe/remoting/WCF .....

+3

The selected answer is far from correct. First of all, p [0] .StandardOutput is already a StreamReader. Secondly, you cannot read the StandardOutput of other processes, you will get an exception!

0
source

All Articles