std = subprocess.PIPE
和檢查在output.If我得到「做」的每一行特定的詞,我手動殺由os.kill子流程:
p = subprocess.Popen(['vprobe' ,'/vprobe/myhello.emt'], shell = False, stdout=subprocess.PIPE, preexec_fn=os.setsid)
while True:
line = p.stdout.readline()
logfile.write(line)
if re.search("done", line):
break
print "waiting"
os.kill(p.pid, signal.SIGINT)
的過程不被打死(我檢查使用UNIX中的「S」命令),但最後我得到一個錯誤:
close failed in file object destructor:
Error in sys.excepthook:
Original exception was:
我認爲很可能是因爲我沒有真正關閉PIPE而殺死了這個過程。任何建議如何我可以手動做到這一點?
'std.close()'? – cdarke
@cdarke'std'是'subprocess.PIPE',它只是'-1'(或它是'-2'?),它沒有'.close()'... – glglgl