언어&플랫폼/python

shell과 pipe 실행하기(subprocess)

cozyboy 2014. 3. 21. 13:45

#!/usr/bin/python


import subprocess


#mount | grep devpts


p1 = subprocess.Popen(["mount"], stdout=subprocess.PIPE)

p2 = subprocess.Popen(["grep", "devpts"], stdin=p1.stdout, stdout=subprocess.PIPE)

out, err = p2.communicate()


print out

print 'err:'+str(err)

           



[결과]

devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)


err:None