2024-04-19 15:04:26 发布
网友
很难弄明白如何用python/exscript编写正则表达式,以便在运行“copy run tftp”时提示与输出相匹配。。。在
例如,提示更改为。。。在
“远程主机[]的地址或名称?”在
然后。。。在
“目标文件名[lab-3560.confg]?”在
我知道在执行命令之前需要设置“set_prompt()”连接执行('copy run tftp')只是不知道正确的语法
有很多方法可以做到这一点,下面是一个例子:
因此,您只需解析返回的提示/text,下面是一个来自link的小示例:
import pexpect switch_ip = "10.0.0.1" switch_un = "user" switch_pw = "s3cr3t" switch_port = "Gi2/0/2" switch_vlan = 300 config = "lab-3560.confg" child = pexpect.spawn('ssh %s@%s' % (switch_un, switch_ip)) child.logfile = sys.stdout child.timeout = 4 child.expect('Address or name of remote host []?') child.sendline(switch_ip) child.expect('Destination filename [lab-3560.confg]?') child.sendline(config)
有很多方法可以做到这一点,下面是一个例子:
因此,您只需解析返回的提示/text,下面是一个来自link的小示例:
相关问题 更多 >
编程相关推荐