Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture external process output

Don't close it as duplicate, since I have a subtle but significant change from the similiar questions:

Is it possible to capture output of an external process (i.e. stdout) in java, when I didn't create the process, and all I know is the process name?

I'm running on windows 7.

EDIT:

If there is a way to do it in other language (C#\C++), then I can write a "CaptureOutput" program that capture the output, write to stdout, and in my java code to launch "CaptureOutput" and read its stdput.

Ugly, but might work.

So answer in other languages is also okay with me.

like image 929
sara Avatar asked Aug 01 '12 13:08

sara


1 Answers

First let me say that what you're asking breaks all the rules of process isolation. If your process does not create the process whose output you want to capture, and you also don't have access to modify the calling process (command shell? service manager? you haven't said which). Then your only chance, and it is a slim one at best, is to inject a thread into the process and while all its other threads are suspended, alter the global stdout (and stderr?). This can only be done by a process with full access privileges to the target process. Performing such surgery on a running process is not for the faint of heart.

like image 117
dex black Avatar answered Sep 20 '22 00:09

dex black