2019独角兽企业重金招聘Python工程师标准>>>
假定shellString为将要通过python执行的shell命令,3种方式如下
import os
status = os.system(shellString),只输出shell返回值
import os
output = os.popen(shellString),只输出shell输出值
import commands
commands官方给的解释(help(commands))为通过os.popen()执行shell命令并返回状态码
status = commands.getstatus(shellString),只输出shell返回值
output = commands.getoutput(shellString),只输出shell输出值
(status,output) = commands.getstatusoutput(shell),输出shell的返回值和输出值