我正在研究一些脚本(在我工作的公司中),这些脚本被加载/卸载到管理程序中,以便在事件发生时触发一段代码。实际卸载脚本的唯一方法是点击Ctrl- C。我正在用 Python 编写一个函数来自动化这个过程
一旦它"done"
在程序的输出中看到字符串,它应该终止vprobe
. 我subprocess.Popen
用来执行命令:
lineList = buff.readlines()
cmd = "vprobe /vprobe/myhello.emt"
p = subprocess.Popen(args = cmd, shell=True,stdout = buff, universal_newlines = True,preexec_fn=os.setsid)
while not re.search("done",lineList[-1]):
print "waiting"
os.kill(p.pid,signal.CTRL_C_EVENT)
如您所见,我正在以buff
读写模式打开的文件描述符中写入输出。我检查最后一行;如果有'done'
,我杀了它。不幸的是,CTRL_C_EVENT
它仅对 Windows 有效。我能为 Linux 做些什么?