What is the difference between subprocess.popen and subprocess.run
<p>I'm new to the <code>subprocess</code> module and the ducumentation leaves me wondering what the difference is between <code>subprocess.popen</code> and <code>subprocess.run</code>.  Is there a difference in what the command does?  Is one just newer?  Which is better to use? </p>

<p><code>subprocess.run</code> <a href="https://docs.python.org/3/library/subprocess.html#subprocess.run" rel="nofollow">was added in Python 3.5</a> as a simplification over <code>subprocess.Popen</code> when you just want to execute a command and wait until it finishes, but you don't want to do anything else meanwhile. For other cases, you still need to use <code>subprocess.Popen</code>.</p>

<p>The main difference is that <code>subprocess.run</code> executes a command and <strong>waits</strong> for it to finish, while with <code>subprocess.Popen</code> you can continue doing your stuff while the process finishes and then just repeatedly call <code>subprocess.communicate</code> yourself to pass and receive data to your process.</p>

<p>Note that, what <code>subprocess.run</code> is actually doing is invoking for you the <code>Popen</code> and <code>communicate</code>, so you don't need to make a loop to pass/receive data nor wait for the process to finish.</p>

<p>Check <a href="https://docs.python.org/3/library/subprocess.html#subprocess.run" rel="nofollow">this site</a> for the information of which parameters of <code>subprocess.run</code> are passed to <code>Popen</code> and which to <code>communicate</code>.</p>

python