subprocess实现管道

1 # shell
2 last | cut -d ' ' -f 1 | sort -u 
 1 #python
 2 from subprocess import Popen,PIPE
 3 
 4 p1 = Popen('last',shell=True,stdout=PIPE)
 5 
 6 p2 = Popen('cut -d ' ' -f 1,shell=True,stdin=p1.stdout,stdout=PIPE)
 7 
 8 p3 = Popen('sort -u',shell=True,stdin=p2.stdout,stdout=PIPE)
 9 
10 >>print p3.stdout.read()

 

posted @ 2014-06-04 09:49  metasequoia  阅读(454)  评论(0编辑  收藏  举报