python 执行sh脚本文件

# 环境:macosx、stackless python & twisted

cmd = '/users/xxx/.../xx.sh' # 全路径或者./相对路径
import subprocess
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while p.poll() == None:
     line = p.stdout.readline()
     print line # 必须执行print,否则一直不返回,原因不明
     result = result + line

你可能感兴趣的:(python)