双击时批处理文件不起作用

时间:2015-01-24 04:29:45

标签: batch-file mysqldump

我有一个批处理文件来做mysqldump。代码是这样的:

@echo off
echo Starting Backup of Mysql Database on server 
for /F "tokens=2,3,4 delims=/ " %i in ('date /t') do set myDate=%k%i%j
set bkupfilename=%myDate%.sql
echo Backing up to file: %bkupfilename%
C:\xampp\mysql\bin\mysqldump  --routines -u <user> -p<pwd>  <database> > D:\MYSQL_DAILY_BACKUPS\"<database>%bkupfilename%"

当我通过输入批处理文件在Win7的cmd控制台上运行它时,它将无法正常工作并抱怨:

C:\xampp\mysql\bin>mysqldumpbatch
Starting Backup of Mysql Database on server
kj was unexpected at this time.

但是当我通过将代码直接复制粘贴到命令提示符来运行它时它运行得很好并生成文件20152401.sql。谁知道为什么?

1 个答案:

答案 0 :(得分:1)

单个%变体仅适用于命令行。尝试替换为%%,如下所示:

@echo off
echo Starting Backup of Mysql Database on server 
for /F "tokens=2,3,4 delims=/ " %%i in ('date /t') do set myDate=%%k%%i%%j
set bkupfilename=%myDate%.sql
echo Backing up to file: %bkupfilename%
C:\xampp\mysql\bin\mysqldump  --routines -u <user> -p<pwd>  <database> > D:\MYSQL_DAILY_BACKUPS\"<database>%bkupfilename%"

如果有效,请告诉我?