我正在运行一个批处理文件:
1. 浏览 C:\ExecutionSDKTest_10.2.2
中的所有 *.属性文件2. 运行它们
3. 将输出日志与引用日志
逐行比较但是 cmd.exe 一直给我抛出这个错误:"!文件名!这时出乎意料。有什么想法吗?
CALL ant clean build compile
REM Run ENG-zzz.properties --> output to ENG-zzz.properties.log in Logs dir
REM loop thru/Run ALL .properties file names from "ExecutionSDKTest_10.2.2" folder
FOR %%G in (C:ExecutionSDKTest_10.2.2*.properties) DO (
set flag=true
Set fileName=%%~nxG
set testNum=!fileName:~0,7!
echo Running:!fileName!
java -jar Test.jar !fileName! > Logs!fileName!.log
ECHO Create: Ref!fileName!.log at C:ExecutionSDKTest_10.2.2Logs
set logPath=C:ExecutionSDKTest_10.2.2Logs!fileName!.log
set refLogPath=C:ExecutionSDKTest_10.2.2Logs!testNum!-Ref.properties.txt
set lnCorrect=true
set errorLnCount=0
REM if ...Ref.txt doesnt Exist --> check certain lines of the log
REM assume ref.txt exists
<!logPath! (
For /F "tokens=*" %%R in (!refLogPath!) DO (
set logLine=
set /p logLine=
set refLogLine=%%R
REM Check line by line of log against refLog
REM assume ALL times have been replaced with: "xx:xx:xx"
REM if corresponding lines mismatch
if NOT !logLine!==!refLogLine! Do (
set lnCorrect=false
REM output to command line: can be put into .log/.txt later
if errorLnCount==1 AND lnCorrect==false DO (
ECHO The following line(s) !fileName! are incorrect against corresponding line(s) in !testNum!-Ref.properties.txt
)
ECHO !logLine!
)
)
)
if lnCorrect=true Do Echo !fileName! Passed
)
Pause
你的语法有点奇怪(简直是错误的)
if lnCorrect=true Do Echo !fileName! Passed
IF
语句不得包含DO
子句。- 比较需要两个等号。
- 没有像
AND
这样的逻辑运算符,OR
- 必须展开变量才能比较它们
所以你的线应该看起来像
if "!lnCorrect!"=="true" Echo !fileName! Passed
另一个错误在行中
if errorLnCount==1 AND lnCorrect==false DO (
这可以重构为
if !errorLnCount!==1 if !lnCorrect!==false (
线路也有问题
ECHO The following line(s) !fileName! are incorrect against
右括号会导致您的问题,因为它关闭了 if 子句和循环。
删除它们或转义它们
ECHO The following line(s^) !fileName! are ... corresponding line(s^) in ...