python subprocess pipe 实时输出日志

* test11.py

import time
print "1"
time.sleep(2)
print "1"
time.sleep(2)
print "1"
time.sleep(2)
print "1"

* test.py

import subprocess

p = subprocess.Popen("python test11.py", shell=True, stdout=subprocess.PIPE)
# None表示正在执行中
while p.poll() is None: 
  out = p.stdout.readline()
  if out != "":
    print out
上一篇:java 框架Nutz


下一篇:项目中的那些事---JavaScript