简体   繁体   English

如何响应 python 中的命令行提示

[英]How to respond to a command line prompt in python

Hello Dear StackOverflow community, I am having a beginner issue.您好,亲爱的 StackOverflow 社区,我遇到了初学者问题。

import subprocess

p = subprocess.Popen(['mysql','-u','root','-p'],
                     stdout = subprocess.PIPE,
                     stdin = subprocess.PIPE)
p.stdin.write("password!\n".encode())
p.stdin.close()

This is the code I am executing to get the login of the SQL server automated.这是我为自动登录 SQL 服务器而执行的代码。 but it doesn't work.但它不起作用。 Please help me to figure out what's wrong.请帮我找出问题所在。

Try removing the .encode() from your write function as the module should handle it for you.尝试从您的写入 function 中删除.encode() ,因为模块应该为您处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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