假定shellString爲將要經過python執行的shell命令,3種方式以下python
import osshell
status = os.system(shellString),只輸出shell返回值
spa
import osget
output = os.popen(shellString),只輸出shell輸出值import
import commandscommand
commands官方給的解釋(help(commands))爲經過os.popen()執行shell命令並返回狀態碼im
status = commands.getstatus(shellString),只輸出shell返回值co
output = commands.getoutput(shellString),只輸出shell輸出值
(status,output) = commands.getstatusoutput(shell),輸出shell的返回值和輸出值