Sunday, February 20, 2011

popen2

这是用来做管道通讯的 module,现在已经 deprecated 了,建议用 subprocess。

提供的函数主要是 popen2/3/4 以及对应的类,返回 stdin、stdout、stderr 这些。下面是一个简单的例子:
#!/usr/bin/python

import popen2

if __name__ == '__main__':
    cout, cin = popen2.popen2( 'grep abc' )
    print >> cin, 'abc\ndef\nghi'
    cin.close()
    for line in cout:
        print line,

No comments:

Post a Comment