0
我的印象是,exit(0)
發信號通知Python解釋器將0返回給系統。例如,子流程調用中的意外縮進
from subprocess import check_call
check_call('python3 -c "exit(0)"', shell=True) # returns 0
但
check_call(['/usr/bin/python3', '-c "exit(0)"'])
回報1:
>>> check_call(['/usr/bin/python3', '-c "exit(0)"'])
File "<string>", line 1
"exit(0)"
^
IndentationError: unexpected indent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/subprocess.py", line 581, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python3', '-c "exit(0)"']' returned non-zero exit status 1
我不能告訴任何地方空間被偷偷溜進這是怎麼回事?
您是否嘗試將'-c「exit(0)」'分成兩個獨立的參數? –
@OliverCharlesworth哎呀。我想這就是答案。 –
每個命令行參數都應作爲單獨的列表項傳遞。您可以使用以下命令從shell命令生成草稿列表:shlex.split('python3 -c「exit(0)'')'。 – jfs