我在后台启动一个脚本。检查脚本是否完成的唯一方法是检查日志。日志每隔几秒更新一次。
out = (os.system(comm)) #I get output of script which is running in background
outs = str(out) # convert it to string
print(type(outs.splitlines()[0])) # select only first line
while 'Job Status : RUN OK (1)' not in outs:
print ('Still running')
sleep(2)
# how I can get this 'outs' var in while loop be updated in each iteration - after 2 seconds
一般如何更新循环中的迭代项? - 就我而言,它是'outs'
答案 0 :(得分:1)
你可以在睡眠后修改它,如下所示
while 'Job Status : RUN OK (1)' not in outs:
print ('Still running')
sleep(2)
outs = str(os.system(comm)))
注意:如果执行正确,os.system返回0,否则返回一些数字。您可能需要使用Subprocess中的Popen来获取cmd行命令的输出