Capture the standard output of a running process

Viewed 270

I am currently testing some programs for my project, I have this program currently running as a daemon I would just like to capture the standard output of this program and maybe the stderr ...

I know strace would have been best as a debugging tool but I guess it does not streamline to my want ..

i see answers on stackoverflow like the subprocess.popen(['ps'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) ... but this start the process .. I just want to hook to a running process and grap output...

any answer or ideas would be appreciated .. if in python, bash or c

2 Answers

To be able to communicate with already running processes you have to set a watchers/listeners on those processes before starting them.

You can see the most common tools for this use, which are Tmux and Screen.

Then I think that you'll be able to do whatever you want with the output of those processes depending on the API provided by the tool you'll use.

This is the first idea I had when I saw the question.

Related