【发布时间】:2017-12-01 09:54:53
【问题描述】:
当我在 Cisco 交换机上运行“显示版本”时,我得到以下输出:
Cisco IOS 软件,C3750E 软件 (C3750E-UNIVERSALK9-M),版本 12.2(58)SE2,发布软件 (fc1) 技术支持:http://www.cisco.com/techsupport Cisco Systems, Inc. 版权所有 (c) 1986-2011。
#
我正在使用 Expect 登录到交换机,运行 show version 命令,并期待该命令的完整输出和确切版本,然后我可以使用以下代码将其输出到屏幕:
send "show version\n"
expect -re "show version.*Version (.*), REL.*#$"
send_user "Command Output:\n$expect_out(0,string)\n\n"
send_user "Version:\n$expect_out(1,string)\n\n"
这一切正常,但是我现在尝试使用 Python 和 Pexpect 复制它。我可以使用 child.before 获得 $expect_out(0,string) 的等价物:
child.sendline(show version')
child.expect('#')
print("\r\n","Command Output:","\r\n",child.before, sep = '')
如何在 Pexpect 中复制 $expect_out(1,string) 以获得准确的版本?
在此先感谢
【问题讨论】: