python 捕获 shell 脚本的输出结果

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]

上一篇:Android学习笔记__2__Android工程目录结构


下一篇:分离的前后台交互