Chinaunix首页 | 论坛 | 博客
  • 博客访问: 471226
  • 博文数量: 135
  • 博客积分: 1860
  • 博客等级: 上尉
  • 技术积分: 1441
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-05 20:39
文章分类
文章存档

2012年(2)

2011年(130)

2009年(2)

2008年(1)

我的朋友

分类:

2011-08-11 16:51:56

 

进程间实时通信的方法

2011年1月18日

17:07

哦,学习了, "communicate()是要等__程退出才返回

 

I was blind but now I can see.

 

  

 

Popen.communicate(input=None)¶

  Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional input argument should be a string to be sent to the child process, or None, if no data should be sent to the child.

 

 

 

 

试了一下,也行

Python code

 

 

 

import subprocess

 

def main():

process1 = subprocess.Popen("python  -u sub.py", shell=False, stdout = subprocess.PIPE, stderr=subprocess.STDOUT)       

#print process1.communicate()[0]

 

while True:

line = process1.stdout.readline()

if not line:

break

print line

 

if __name__ == \'__main__\':

main()

 

Pasted from <>

 

阅读(459) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~