【发布时间】:2015-01-19 17:24:05
【问题描述】:
#运行shell命令的函数
def OSinfo(runthis):
#Run the command in the OS
osstdout = subprocess.Popen(runthis, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
#Grab the stdout
theInfo = osstdout.stdout.read() #readline()
#Remove the carriage return at the end of a 1 line result
theInfo = str(theInfo).strip()
#Return the result
return theInfo
#flash raid固件
OSinfo('MegaCli -adpfwflash -f ' + imagefile + ' -noverchk -a0')
#固件闪存的返回状态
?
推荐使用“subprocess.check_output()”的一个资源,但是,我不确定如何将其合并到函数 OSinfo() 中。
【问题讨论】:
-
你只是想检查返回码是0吗?
-
是的。检查是否为零,如果不是则退出1。
-
所以你不关心任何输出,只关心非 0 退出状态?
标签: python subprocess exit-code