【发布时间】:2015-11-03 16:50:22
【问题描述】:
我正在使用 Python 和 pexpect 来自动化网络设备的 CLI 界面。 问题是我不能使用 pexpect 发送需要“是”/“否”确认的命令。 我认为这是因为 pexpect 与问题不匹配。
child = pexpect.spawn ('ssh -p <port> user@192.168.1.1')
child.expect ("password: ")
child.sendline ('userPass')
child.expect ('> ')
child.sendline('show')
child.expect('> ')
logging.info(child.before)
# works fine untill now - it connects to the box and prints the show output
child.sendline ('reset')
logging.info(child.before)
# this command prints the same thing as previous child.before
logging.info('This line gets printed.')
child.expect ("<additional text> Are You sure? [no,yes] ")
logging.info('This line does not get printed.')
child.sendline ('yes')
【问题讨论】:
标签: python python-2.7 command-line-interface pexpect