In Python subprocess, what is the difference between using Popen() and check_output()?
<p>Take the shell command "cat file.txt" as an example. </p>

<p>With Popen, this could be run with</p>

<pre><code>import subprocess
task = subprocess.Popen("cat file.txt", shell=True,  stdout=subprocess.PIPE)
data = task.stdout.read()
</code></pre>

<p>With check_output, one could run</p>

<pre><code>import subprocess
command=r"""cat file.log"""
output=subprocess.check_output(command, shell=True)
</code></pre>

<p>These appears to be equivalent. What is the difference with regards to how these two commands would be used? </p>

<p>From <a href="https://docs.python.org/3/library/subprocess.html#exceptions" rel="nofollow">the documentation</a>:</p>

<blockquote>
  <p><code>check_call()</code> and <code>check_output()</code> will raise <code>CalledProcessError</code> if the called process returns a non-zero return code.</p>
</blockquote>

python bash shell subprocess