Catching and outputting stderr at the same time with python's subprocess

Posted by Mediocre Gopher on Stack Overflow See other posts from Stack Overflow or by Mediocre Gopher
Published on 2012-10-14T20:16:38Z Indexed on 2012/10/14 21:37 UTC
Read the original article Hit count: 193

Filed under:
|
|
|
|

(Using python 3.2 currently)

I need to be able to:

  • Run a command using subprocess
  • Both stdout/stderr of that command need be printed to the terminal in real-time (it doesn't matter if they both come out on stdout or stderr or whatever
  • At the same time, I need a way to know if the command printed anything to stderr (and preferably what it printed).

I've played around with subprocess pipes as well as doing strange pipe redirects in bash, as well as using tee, but as of yet haven't found anything that would work. Is this something that's possible?

© Stack Overflow or respective owner

Related posts about python

Related posts about subprocess