我的python脚本卡在data = p1.stdout.readline()中

时间:2015-10-29 19:50:59

标签: python linux bash shell

#!/usr/bin/env python
import sys
import subprocess

p1 = subprocess.Popen(["sudo su"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
print "ggg"
m=p1.poll()
print m

#p2 = subprocess.Popen(["apt-get upgrade"], stdout=p1.stdin, stdin=subprocess.PIPE)
print "111"
p1.stdin.write("apt-get upgrade\n")
p1.stdin.flush()
while True :
    data = p1.stdout.readline() #block / wait

    print data

    if not data:

        break

print "222"
p1.stdin.write("apt-get update\n")
p1.stdin.flush()
while True :
    data = p1.stdout.readline() #block / wait
    print data
    if (data==''):
        break

output = p1.communicate()[0]
print output

我的脚本卡在data = p1.stdout.readline()

0 个答案:

没有答案