Pexpect not working for interactive analysis?

I am trying to parse the boot sequence of a device. I telnet into a terminal server which connects me to the serial port of the device.

The following script works and logs me, which means the terminal is responsive to the script and sendline:

import pexpect
child = pexpect.spawn ('telnet x.x.x.x yyyy')
child.expect ('login: ')
child.sendline ('anonymous')
child.expect ('Password:')
child.sendline ('noah@example.com')

      

The following failed:

import pexpect
child = pexpect.spawn ('telnet x.x.x.x yyyy')
child.expect ('Hit [Enter] to boot immediately, or space bar for command prompt.', timeout=300)
child.send ('\x20')
print child.before

      

My goal is when the device boots up, it just outputs a line with the expected line, which is somewhere in the middle of the scroll.

The above script cannot match. After further debugging, "child.before" shows me the last line before the login prompt. What is the reason for the refusal?

+3


source to share


1 answer


Bingo! The evacuation character was what I was missing.



+1


source







All Articles