subprocess.CalledProcessError: what *is* the error?
<pre><code>import subprocess

cmd = "grep -r * | grep jquery"
print cmd

subprocess.check_output(cmd, shell=True)
</code></pre>

<p><strong>subprocess.CalledProcessError: Command 'grep -r * | grep jquery' returned non-zero exit status 1</strong></p>

<p>I can execute that command in my shell without issues. How can I see the <strong>actual</strong> error in python?</p>

<p><em>The snippet is part of a larger script which takes multiple arguments and chains the grep commands + adds some excludes (I don't need to grep log files or minified JavaScript. Hence the pedantic syntax.</em></p>

<p><em>Python 2.7.10</em></p>

<p>"non-zero exit status" means that the <em>command you ran</em> indicated a status other than success. For <code>grep</code>, the documentation explicitly indicates that an exit status of 1 indicates no lines were found, whereas an exit status more than 1 indicates that some other error took place.</p>

<p>To quote the manual:</p>

<blockquote>
  <p><strong>EXIT STATUS</strong> - The grep utility exits with one of the following values:</p>

<pre><code>0     One or more lines were selected.
1     No lines were selected.
&gt;1    An error occurred.
</code></pre>
</blockquote>

<hr>

<p>By the way -- if you want to look for the string <code>jquery</code> in all files under the current directory (recursively), use <code>grep -r jquery .</code>; <code>grep -r *</code> searches for <em>the name of the first file in your directory</em> inside <em>the contents of all other files in your directory</em>.</p>

python subprocess