python 捕获 shell/bash 脚本的输出结果实例
#!/usr/bin/python
##getsubprocessmodule
importsubprocess
##calldatecommand##
p=subprocess.Popen("date",stdout=subprocess.PIPE,shell=True)
##Talkwithdatecommandi.e.readdatafromstdoutandstderr.Storethisinfointuple
##Interactwithprocess:Senddatatostdin.Readdatafromstdoutandstderr,
##untilend-of-fileisreached.Waitforprocesstoterminate.Theoptionalinput
##argumentshouldbeastringtobesenttothechildprocess,orNone,
##ifnodatashouldbesenttothechild.##
(output,err)=p.communicate()
##Waitfordatetoterminate.Getreturnreturncode##
p_status=p.wait()
print"Commandoutput:",output
print"Commandexitstatus/returncode:",p_status
##from:http://www.cyberciti.biz/faq/python-run-external-command-and-get-output/
以上就是小编为大家带来的python捕获shell/bash脚本的输出结果实例全部内容了,希望大家多多支持毛票票~