简体   繁体   English

密码通过命令行输入后如何按“ Enter”键?

[英]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.

相关问题 传递命令行参数后如何停止删除双引号? - How do I stop removing double quotes after passing command-line argument? 我如何使用 selenium python 在 cr 按钮上按下 enter - how do i press enter on a cr-button with selenium python QTableView当我按下回车或返回按钮时如何进入编辑模式? - QTableView how do I enter edit mode when I press enter or return button? 如何通过命令行将参数赋予python脚本功能? - How can I give parameters to a function of a python script through the command-line? 如何在subprocess.call()之后输入密码 - How do I enter a password after subprocess.call() 如何使用 Python 类创建一个简单的登录命令行程序? - How do I create a simple login command-line program using Python classes? 如何从命令行编译 Visual Studio 项目? - How do I compile a Visual Studio project from the command-line? PySpark:如何在工人上安装linux命令行工具? - PySpark: How do I install a linux command-line tool on workers? 如何使用optparse将命令行参数拆分为选项和位置参数? - How do I use optparse to just split the command-line arguments into options and positional args? 如何在 Chrome OS 上使用命令行 arguments 运行 Python 脚本? - How do I run a Python script WITH command-line arguments on Chrome OS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM