1

私はバッチファイルを実行しています:
1. C:\ExecutionSDKTest_10.2.2 のすべての *.properties ファイルを調べます
2. それらを実行します
3. 出力されたログを 1 行ずつ ref ログと比較します
しかし、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. 比較には2つの等号が必要です。
  3. のような論理演算子はありませんANDOR
  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 に答える