37,720
社区成员
发帖
与我相关
我的任务
分享
import subprocess
def main():
process1 = subprocess.Popen("python sub.py", shell=False, stdout = subprocess.PIPE, stderr=subprocess.STDOUT)
print process1.communicate()[0]
if __name__ == '__main__':
main()
import subprocess
def main():
process1 = subprocess.Popen("ping 128.101.1.4 -n 1", shell=True, stdout = subprocess.PIPE, stderr=subprocess.STDOUT)
process2 = subprocess.Popen("ping 128.101.1.4 -n 3", shell=False, stdout = subprocess.PIPE, stderr=subprocess.STDOUT)
process3 = subprocess.Popen("ping 128.101.1.4 -n 6", shell=False, stdout = subprocess.PIPE, stderr=subprocess.STDOUT)
while 1:
time.sleep(1)
ret1 = subprocess.Popen.poll(process1)
ret2 = subprocess.Popen.poll(process2)
if ret1 is None:
print process1.pid, " running"
else:
print process2.pid, " Termined"
if ret2 is None:
print process2.pid, " running"
else:
print process2.pid
win32api.TerminateProcess(int(process3._handle), -1)
break
#if __name__ == '__main__':
main()
import subprocess
import time
p = subprocess.Popen('ping 127.0.0.1 -n 10', 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("python -u sub.py", shell=False, stdout = subprocess.PIPE, stderr=subprocess.STDOUT) # modify to python -u
print process1.communicate()[0]
if __name__ == '__main__':
main()
import subprocess
def main():
process1 = subprocess.Popen("python -u sub.py", shell=False, 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()