python创建子进程输出

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

import subprocess
sp = subprocess.Popen('ping 127.0.0.1', shell=True ,stdout=subprocess.PIPE)
while True:
    line = sp.stdout.readline()
    if not line:break
    print line
if sp.wait() == 0:
    print 'sub process execute ok'
import subprocess  
import time  
   
p = subprocess.Popen('ping 114.114.114.114',shell=True,  stdout=subprocess.PIPE)  
while p.poll() == None:  
    print p.stdout.readline()  
    time.sleep(1)  
print p.stdout.read()     
print 'returen code:', p.returncode 
import subprocess  
   
def main():  
    process1 = subprocess.Popen("ping 114.114.114.114", shell=True, stdout = subprocess.PIPE, stderr=subprocess.STDOUT)          
    #print process1.communicate()[0]  
   
    while True:  
        line = process1.stdout.readline()  
        if not line:  
            break  
        print line  
       
if __name__ == '__main__':  
    main()  

 

转载于:https://my.oschina.net/9199771/blog/903287

你可能感兴趣的:(python创建子进程输出)