简体   繁体   中英

pexpect and sending an "Enter Key" issues

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.

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')

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.

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

.sendline() is equivalent to .sendline('') that is equivalent to .send('') + .send(self.linesep) that is likely has the same effect as .send('\n') ( '\n' == '\012' , '\r' == '\015' ). You could also try .send('\r\n') (I'm not sure who is responsible for the terminal line discipline).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM