我用subprocess
的check_output()
函數兩種方式,找到結果不一樣,我不知道爲什麼。子過程使用兩種方式,但結果不一樣
第一種方式:
from subprocess import check_output as qc output = qc(['exit', '1'], shell=True)
方式二:
from subprocess import check_output as qc output = qc(['exit 1'], shell=True)
錯誤:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/work/cloud/python2.7_64/lib/python2.7/subprocess.py", line 544, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['exit 1']' returned non-zero exit status 1
二方式是對的,但第一種方式爲什麼不正確?
試試'qc('exit 1',shell = True)'。我想它正在執行'「exit 1」' –
相關:[subprocess.call using string vs using list](http://stackoverflow.com/q/15109665/4279) – jfs