Get only stderr output from subprocess.check_output
<p>I want to run an external process in python, and process its <code>stderr</code> only.</p>

<p>I know I can use <code>subprocess.check_output</code>, but how can I redirect the stdout to <code>/dev/null</code> (or ignore it in any other way), and receive only the <code>stderr</code>?</p>

<p>I found a simple trick:</p>

<pre><code>import subprocess
stderr_str = subprocess.check_output('command 2&gt;&amp;1 &gt;/dev/null')
</code></pre>

<p>This will filter out the stdout, and keeps only the stderr.</p>

python python-2.7 subprocess stderr