如何暂停python脚本以进一步执行,但子进程必须运行指定的时间

问题描述 投票:0回答:1
p = subprocess.Popen("exec " +runcmd, stdout=subprocess.PIPE, shell=True)
            while p.poll() == None:
            #while True:
                    output = p.stdout.readline()
                    print (output)
                    if output == '' and p.poll is not None:
                            break
                    if output:
                            str = output.strip()
                            if '"Activate"' in str:
                                    print ("pause initiated")

这里当stdout / output在日志中找到Activate我想暂停脚本但是它们的子进程执行必须继续指定的时间??如果我错了,请帮助并纠正我

python-2.7 subprocess
1个回答
0
投票

我仍然不是100%确定你在寻找什么但是以下脚本:

  1. 启动runcmd(在命令之前不需要exec
  2. 等到它在输出中找到"Activate"(或者在程序结束之前停止,qzxswpoi调用已经正确)
  3. 睡10秒
  4. 杀死进程并打破循环

.poll()
© www.soinside.com 2019 - 2024. All rights reserved.