我试图从Python文件运行命令:密码被用作命令
p = subprocess.Popen("mysqldump -h" + hostname + " -u" + mysql_user + " --password=" + mysql_pw + " " + db + " > dump_" + hostname + "_" + timestamp + ".sql", shell=True)
但--password=
甚至-p
不断得到绞死了我的密码字符串
密码与此类似结构:
[email protected]&sfeafxegwa
命令行错误:
'sfeafxegwa' is not recognized as an internal or external command,
operable program or batch file.
使用try:
与
shell=True
的问题是,最好在旧版本的文档的解释'&'被bash解释,并将命令的前半部分作为自己的进程分叉,然后在下半部分失败。上面提到的将会在密码字符串周围添加单引号。 –此外,恕我直言,这将是更多使用格式字符串可读 –
@MattClark,这很有道理,但我仍然收到错误:''sfeafxegwa'' ',这次用额外的'''非常非常真实@tobias_k - 谢谢! –