运行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
#闪存raid固件
OSinfo('MegaCli -adpfwflash -f ' + imagefile + ' -noverchk -a0')
#固件闪存的返回状态
?
建议使用“subprocess.check_output()”的一个资源,但是,我不确定如何将其合并到函数OSinfo()中。
如果您只想
return 1
如果存在非零退出状态,请使用check_call
,任何非零退出状态都将引发我们捕获的错误,否则return 1
将是osstdout
:如果传递参数列表,则也不需要shell=True。
与其使用} 来获取子进程的
osstdout.stdout.read()
来获取子进程的stdout
,不如使用^{stdout
,这将阻塞直到子进程终止。完成后,属性osstout.returncode
将被设置为包含子流程的返回代码。你的函数可以写成
相关问题 更多 >
编程相关推荐