nsJHDM
nsJHDM

Reputation: 21

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.

Upvotes: 1

Views: 14900

Answers (2)

Sam
Sam

Reputation: 556

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

Upvotes: 0

jfs
jfs

Reputation: 414069

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

Upvotes: 0

Related Questions