全部博文(135)
分类:
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 <>