How can I capture the stdout output of a child process?

Something like this: import subprocess process = subprocess. Popen("yourcommand", stdout=subprocess. PIPE) result = process.communicate()0.

And yes I'm interested in printing output after process is finished. Also where you have "yourcommand" does the exe extension go there? – Tyler May 28 '09 at 20:57 1 "result" will be the entire output of "yourcommand".

You can then process that string (or bytes object, in Py3.0) to find the line you're looking for. – Dietrich Epp May 28 '09 at 21:08 1 the 0 means the first element of the tuple returned (stdout, stderr); you may process result, which will be a string, to your liking, e.g. To find a particular line. "yourcommand" is your full command, eventually a full path to a command if the command ist not on path (at least on *nix).

– miku May 28 '09 at 21:08.

Paolo's solution is perfect if you are interested in printing output after the process has finished executing. In case you want to poll output while the process is running you have to do it this way: process = subprocess. Popen(cmd, stdout=subprocess.

PIPE) while True: out = process.stdout. Readline(1) if out == '' and process.poll()! = None: break if out.

Startswith('myline'): sys.stdout. Write(out) sys.stdout.flush().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions