问题
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.
回答1:
.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).
回答2:
sendline() should be work. You can refer to the implementation of pxssh in pexpect. https://github.com/pexpect/pexpect/blob/master/pexpect/pxssh.py
来源:https://stackoverflow.com/questions/29217645/pexpect-and-sending-an-enter-key-issues