我正在尝试从python文件运行命令:
p = subprocess.Popen("mysqldump -h" + hostname + " -u" + mysql_user + " --password=" + mysql_pw + " " + db + " > dump_" + hostname + "_" + timestamp + ".sql", shell=True)
但是--password=
甚至-p
一直挂在我的密码字符串上
密码与此结构类似:
Z@F&sfeafxegwa
命令行错误:
'sfeafxegwa' is not recognized as an internal or external command,
operable program or batch file.
您需要引用密码来保护shell元字符(例如
&
)不被shell特别对待,例如:但是,如果密码本身可以包含引号,这将不起作用。更好的选择是将参数列表传递给
subprocess
,然后自己进行重定向:正如评论中已经提到的,不要使用
shell=True
。见https://docs.python.org/3/library/subprocess.html#security-considerations。你知道吗将参数列表直接传递给
Popen
构造函数,而不是让shell进行拆分。你知道吗shell=True
的问题可以在旧版本的文档中得到更好的解释:https://docs.python.org/2/library/subprocess.html#frequently-used-arguments相关问题 更多 >
编程相关推荐