简体   繁体   English

从Python控制Windows命令提示符

[英]Control Windows Command Prompt from Python

I am trying to programmatically shut down mysqld from python on a windows 7 machine. 我正在尝试以编程方式在Windows 7计算机上从python关闭mysqld。

I have tried the following commands in windows command prompt manually: 我已经在Windows命令提示符中手动尝试了以下命令:

"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqladmin" -u demo shutdown -p demopw

I then receive the following prompt: 然后,我收到以下提示:

Enter Password:

After I manually type in the password, mysqld shuts down. 手动输入密码后,mysqld关闭。

My problem is, I need to do this automatically within python. 我的问题是,我需要在python中自动执行此操作。 I have read one or two other posts that I could find, and have searched for quite a while for an answer that works. 我已经阅读了我可以找到的另外一两个帖子,并且已经搜索了很长时间以找到有效的答案。 Thus far, I have tried many variations with popen, and subprocess.Popen, to no avail. 到目前为止,我已经尝试了popen和subprocess.Popen的许多变体,但均无济于事。

Thanks in advance. 提前致谢。

The -p argument to mysql and mysqladmin et al is funky in that you absolutely can not have a space between the -p and the password. mysqlmysqladmin等人的-p参数很时髦,因为-p和密码之间绝对不能有空格。

So try 所以尝试

"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqladmin" -u demo -pdemopw shutdown

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

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