[BAT]批处理脚本双击可运行,但在定时计划任务中无法执行(当前工作路径不对导致的)

一开始,红色部分我是用set AutoPath=%cd%,双击可执行,但是将这个批处理脚本放在定时任务中无法执行,后来发现在定时执行的时候,当前工作路径不是批处理脚本所在的路径,而是C:/Windows/System32,所以需要用以下方法改变一下当前工作路径。

@echo off
color 0a

echo autotest beginning,Please Wait... ...

set AutoPath=%~dp0
%AutoPath:~0,2% 
pushd %AutoPath%

cd /d %AutoPath%
set JmeterPath=..\..\..\
echo AutoPath=%AutoPath%
echo JmeterPath=%JmeterPath%

forfiles /p %AutoPath%Result /m *.jtl -d -7 /c "cmd /c del /f @path">nul 2>nul
forfiles /p %JmeterPath%extras /m *.html -d -7 /c "cmd /c del /f @path">nul 2>nul

ant -f CIMSmokeTest.xml>%AutoPath%\Result\log.txt

pause

posted on 2013-09-17 15:19  张缤分  阅读(2584)  评论(0编辑  收藏  举报

导航