简体   繁体   中英

pexpect for interactive parsing failing?

I am trying to parse the bootup sequence of a device. I connect using telnet to the terminal server, which connects me to the serial port of the device.

The following script works and logs me in, which means the terminal is responsive to the script & 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 fails:

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 aim is when the device boots, it just does line-oriented output with my expected string coming somewhere in the middle of scroll.

The above script is unable to match. Upon further debugging "child.before" shows me last line prior to login prompt. What is the cause of the failure?

Bingo! The escape character was what I was missing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM