以shell命令「cat file.txt」爲例。在Python子流程中,使用Popen()和check_output()有什麼區別?
隨着POPEN,這可能是與
import subprocess
task = subprocess.Popen("cat file.txt", shell=True, stdout=subprocess.PIPE)
data = task.stdout.read()
隨着check_output運行,一個可以運行
import subprocess
command=r"""cat file.log"""
output=subprocess.check_output(command, shell=True)
這些似乎是等價的。關於如何使用這兩個命令有什麼區別?