简体   繁体   English

Windows上使用任务计划程序未完全执行批处理文件

[英]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. 我有以下批处理代码,当我双击该批处理时,该代码可以正常运行,但是当我尝试通过Windows Task Scheduler运行它时,它只能部分运行。 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. 基本上,代码删除ergo的所有行,一直运行到mysql -e "DELETE FROM software_it.hardware" -u root并且不再执行。 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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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