Mer*_*lin 0 python shell command-line
我有mysql dump命令,我想从Windows shell或命令提示符运行.我用shell它确实有效.
d= 'BkSql_'+datetime.datetime.now().strftime("%Y-%m-%d")+".sql"
fn = dn+d
cmd="""mysqldump -u hapopdy -p > %s""" %fn
print cmd
Run Code Online (Sandbox Code Playgroud)
编辑::::::: -p需要是原始输入.
使用子进程模块
import subprocess
subprocess.call(cmd)
Run Code Online (Sandbox Code Playgroud)
如果您正在运行shell命令add shell=True
subprocess.call(cmd, shell=True)
Run Code Online (Sandbox Code Playgroud)