当前位置:主页 > 软件编程 > Python代码 >

python 捕获shell脚本的输出结果实例

时间:2021-02-24 09:35:59 | 栏目:Python代码 | 点击:

import subprocess
output =Popen(["mycmd","myarg"], stdout=PIPE).communicate()[0]


import subprocess
p = subprocess.Popen(['ls','-a'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print out

 

# work on Unix/Linux only

import commands
print commands.getstatusoutput('wc -l file')[1]

您可能感兴趣的文章:

相关文章