我正在尝试使用不同的方法在执行命令时打印Popen
的输出,到目前为止,它们都没有对我有效,我缺少什么?如何使用实时输出POPEN
import signal, os
import sys
import subprocess
import argparse
from subprocess import Popen, PIPE, STDOUT
import threading
from time import sleep
import time
from subprocess import Popen, PIPE, STDOUT
cmd = "python \\\\snowcone\\builds724\\INTEGRATION\\BUILD-117493-STD.INT-1\\uncommon\\build\\script.exe -s ufs"
#proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc = subprocess.Popen(cmd.split(' '), stderr=subprocess.PIPE)
print "Executing %s"%cmd
# Set the signal handler and a 5-second alarm
signal.signal(signal.SIGALRM, proc)
signal.alarm(5)
with proc.stderr:
for line in iter(proc.stderr.readline, b''):
print "LINE"
print line,
proc.wait() # wait for the subprocess to exit