In Python subprocess, what is the difference between using Popen() and check_output()?
问题 Take the shell command "cat file.txt" as an example. With Popen, this could be run with import subprocess task = subprocess.Popen("cat file.txt", shell=True, stdout=subprocess.PIPE) data = task.stdout.read() With check_output, one could run import subprocess command=r"""cat file.log""" output=subprocess.check_output(command, shell=True) These appears to be equivalent. What is the difference with regards to how these two commands would be used? 回答1: Popen is the class that defines an object