Discarding STDERR generated during subprocess.popen

Daniel Kluev dan.kluev at gmail.com
Mon Aug 23 20:16:43 CEST 2010


On Tue, Aug 24, 2010 at 4:38 AM, Leon Derczynski <leon at dcs.shef.ac.uk>wrote:

> Hi,
>
> I would like to run an external program, and discard anything written
> to stderr during its execution, capturing only stdout. My code
> currently looks like:
>
> def blaheta_tag(filename):
>        blaheta_dir = '/home/leon/signal_annotation/parsers/blaheta/'
>        process = subprocess.Popen([blaheta_dir + 'exec/funcTag',
> blaheta_dir + 'data/', filename], cwd=blaheta_dir,
> stdout=subprocess.PIPE)
>        process.wait()
>        return process.communicate()[0]
>
> This returns stdout, and stderr ends up printing to the console. How
> can I disregard anything sent to stderr such that it doesn't appear on
> the console?
>

Just add `stderr=subprocess.PIPE` keyword in the Popen call.

-- 
With best regards,
Daniel Kluev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100824/e67b9078/attachment.html>


More information about the Python-list mailing list