1

我正在运行一个批处理文件:
1. 遍历 C:\ExecutionSDKTest_10.2.2 中的所有 *.properties 文件
2. 运行它们
3. 逐行比较输出日志与 ref log
但是 cmd.exe 一直在抛出我此错误:“!fileName!此时出乎意料。有什么想法吗?

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.2\Logs
set logPath=C:\ExecutionSDKTest_10.2.2\Logs\!fileName!.log
set refLogPath=C:\ExecutionSDKTest_10.2.2\Logs\!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
4

1 回答 1

1

你的语法有点奇怪(这是错误的)
if lnCorrect=true Do Echo !fileName! Passed

  1. IF语句不能有DO子句。
  2. compare 需要两个等号。
  3. 没有像AND,这样的逻辑运算符OR
  4. 必须扩展变量以便能够比较它们

所以你的线应该看起来像
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 ...
于 2012-06-29T20:56:58.650 回答