Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | Email

7.3. Popen

#!/usr/bin/python

from  subprocess import *
p = Popen(["cat", "-n"], bufsize=1024,stdin=PIPE,
                    stdout=PIPE, close_fds=True)

(fin, fout) =  (p.stdin, p.stdout)
for i in range(10):
   fin.write("line" + str(i))
   fin.write('\n')
   fin.flush()
   print fout.readline(),