Enter键命令有时在预期中不起作用

问题描述 投票:0回答:1

我正在pexpect脚本下运行,以登录Avocent控制台服务器以连接到网络设备。输入服务器密码后,需要按“ Enter键”以出现提示。为此,我尝试了child.sendline()child.send('\n')child.sendcontrol ('m'),但这些都不起作用。我尝试过child.send('\r'),但它会间歇性地工作。不知道是什么原因引起的。

[我看到脚本在等待输入键时卡住,如果我手动登录到控制台并通过键盘发送Enter键,则pexpect脚本会继续。

这是我的代码段:

child = pexpect.spawn('ssh [email protected]', timeout=120)
child.expect('Password:', timeout=60)
child.sendline(avocentpswd)
child.send('\r')
print "enter key sent"
cli = child.expect(['cisco#' , 'cisco>'])

使用pexpect == 4.7.0Python 2.7.5操作系统:RHEL v7

有人可以帮忙。

我检查了提出的问题,但这没有帮助:pexpect and sending an "Enter Key" issues

python-2.7 ssh enter pexpect pxssh
1个回答
0
投票

您可能只需要等待一两秒钟,以使ssh完成连接并将tty模式重置为echo。尝试在发送import time;time.sleep(5)之前添加一个\r,如果可行,请使用类似(未经测试)的循环:

© www.soinside.com 2019 - 2024. All rights reserved.