[英]How do I press “Enter” button after the password is passed through command-line?
I used the following code, which runs the command and prompts password. 我使用了以下代码,该代码运行命令并提示输入密码。 When I entered the password using sendline, for some reason the login is not happening. 当我使用sendline输入密码时,由于某种原因未登录。
How to debug this and ensure the "Enter" button is sent? 如何调试它并确保发送“ Enter”按钮?
Code: 码:
child = pexpect.spawn('tool --server=commander.company.com login username',logfile=sys.stdout)
child.expect('Password:')
child.sendline('com0201')
sendline()
will automatically send the new line character defined in os.linesep
, so you shouldn't need to do anything special to send the "enter button". sendline()
将自动发送os.linesep
定义的os.linesep
,因此您无需执行任何特殊操作即可发送“输入按钮”。
You have logging enabled; 您已启用日志记录; what output do you see? 您看到什么输出?
Something else to try is to child.interact()
after you send the password. 其他尝试是在发送密码后访问child.interact()
。 This will let you interact with the child process and might provide some clue if there is a problem. 这将使您与子进程进行交互,并且在出现问题时可能会提供一些线索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.