pexpect 并发送“回车键"问题 [英] pexpect and sending an "Enter Key" issues

查看:102
本文介绍了pexpect 并发送“回车键"问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 python 2.7 中使用 pexpect.我目前正在编写一个脚本来登录跳转服务器,然后登录到一些 cisco 设备以自动方式执行一些操作.

I am using pexpect with python 2.7. I am currently writing a script to login to a jump server and then subsequently login to some cisco devices to perform some operations in an automated way.

在登录过程中有一个阶段,我需要通过按键盘上的Enter/Return"来发送一个空行.在阅读了许多帖子和其他论坛后,我尝试了以下方法:

There is a stage during the login process, where I need to send just a blank line by pressing 'Enter/Return' on the keyboard. After reading many of the posts and other forums, I have tried the following:

<handler>.sendline()
<handler>.sendline('')
<handler>.send('\013')

然而,这些似乎都不适合我.当我手动登录到服务器并尝试按 Enter/Return 时,我在屏幕上看到一个C"并且登录过程继续进行.

However, none of these seem to work for me. When I do login manually to the server and attempt to hit Enter/Return, I see a "C" on the screen and the login process proceeds forward.

我不确定C"是什么意思,但是如果有人可以在这里提供帮助或提供一些见解,那将非常有帮助.

I am not sure what the "C" means, however if anyone can help or provide some insight here, it would be really helpful.

推荐答案

sendline() 应该可以工作.可以参考pexpect中pxssh的实现.https://github.com/pexpect/pexpect/blob/master/pexpect/pxssh.py

sendline() should be work. You can refer to the implementation of pxssh in pexpect. https://github.com/pexpect/pexpect/blob/master/pexpect/pxssh.py

这篇关于pexpect 并发送“回车键"问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆