I am trying to write a script with pexpect
where I need to take huge output within 30 minutes before expecting the prompt.
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
Tried keeping child.timeout
, but dint help.
Tried passing timeout with child.expect
, but dint help.
Is there any way I can expect some prompt when output is huge and time required to reach to the prompt is around 30 minutes?
The EOF exception means that your child process exited before your command timed out. To handle this case you can provide a list of expectations and handle the logic for each of them separately
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