简体   繁体   中英

batch file not executing completely using task scheduler on windows

I have the following batch code, the code executes fine when I double click on the batch but when I try to run it through windows task scheduler, it only runs partially. I am unable to understand why.

Basically the code deletes all the rows ergo, runs until mysql -e "DELETE FROM software_it.hardware" -u root and does not execute further. Any help would be great.

@ECHO OFF
setlocal enabledelayedexpansion
mysql -e "DELETE  FROM software_it.hardware" -u root 
FOR %%f IN ("*.csv") DO (
  set old=%%~dpnxf
  set new=!old:\=\\!
  mysql -e "load data local infile '"!new!"' into table software_it.hardware  COLUMNS TERMINATED BY ',' IGNORE 1 ROWS" -u root
  echo %%~nxf DONE
)

When run from task scheduler it is likely that the 'current directory' will be different from that used when you run the script directly. I would therefore suggest adding the following third line :

IF /I "%CD%\" NEQ "%~dp0" PUSHD "%~dp0"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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