subprocess.run
was added in Python 3.5 as a simplification over subprocess.Popen
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 subprocess.Popen
.
The main difference is that subprocess.run
executes a command and waits for it to finish, while with subprocess.Popen
you can continue doing your stuff while the process finishes and then just repeatedly call subprocess.communicate
yourself to pass and receive data to your process.
Note that, what subprocess.run
is actually doing is invoking for you the Popen
and communicate
, so you don't need to make a loop to pass/receive data nor wait for the process to finish.
Check the official documentation for information of which parameters of subprocess.run
are passed to Popen
and which to communicate
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…