- 论坛徽章:
- 0
|
求助各位,
我需要执行一段脚本调用jar文件来测试某个东西,执行这段脚本需要好几个小时,则需要pexpect来取到执行完结果的相关数据,在退出相关脚本,执行后面脚本,但是使用如下脚本后。
自动执行脚本是原来单独执行脚本时间的好几倍,是由于执行while条件造成的吗?是由于TIMEOUT的默认时间问题?
求指教,该如何改进,shell的 expect是否会更有效率些。- def run(self):
- try:
- child = pexpect.spawn(self.path)
- child.logfile = sys.stdout
- child.expect('xxxxx >')
- child.sendline('run xxxxx')
- while 1:
- test = '.*xxxx result file generated.*'
- index = child.expect([test, pexpect.EOF, pexpect.TIMEOUT])
- if index == 0:
- break
- elif index == 1:
- pass
- elif index == 2:
- pass
- child.sendline('exit')
- child.sendcontrol('c')
- child.interact()
- except OSError:
- sys.exit(0)
复制代码 |
|