如何处理在 30 分钟内显示的巨大输出,然后期待提示与 pexpect



我正在尝试编写一个带有pexpect的脚本,我需要在 30 分钟内获得巨大的输出,然后才能期待提示。

child.sendline('abc')
child.expect('.*:abc.*')
child.sendline('test')
# child.timeout=1500
# There will be huge output displayed for 30 minutes here
child.expect('.*:abc.*', timeout=1500)
status = child.after
print status

尝试保持child.timeout,但无济于事。尝试用child.expect传递超时,但无济于事。

当输出很大并且达到提示所需的时间约为 30 分钟时,有什么方法可以期待一些提示?

EOF 异常意味着子进程在命令超时之前退出。要处理这种情况,您可以提供期望列表并分别处理每个期望的逻辑

result = child.expect(['.*:abc.*', pexpect.TIMEOUT, pexpect.EOF], timeout=1500)
if result == 1:
    # code to handle case where the expected string .*:abc.* was caught
if result == 2:
    # code to handle timeout exception
if result == 3:
    # code to handle EOF exception

最新更新