2012-06-29 44 views
1

我運行一個批處理文件:
1.進入直通ALL *用C .properties文件:\ ExecutionSDKTest_10.2.2
2.輸出的日誌,日誌參考線運行它們
3.比較線
但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 
+0

我沒有看到一個'SETLOCAL enableDelayedExpansion'任何地方,但你顯然嘗試使用延遲擴展。它可以這麼簡單嗎? – dbenham

+0

@dbenham:可以啓用CMD命令行開關。沒有多少人可能知道它,當然... –

回答

1

你的語法是有點古怪(這是完全錯誤的)
if lnCorrect=true Do Echo !fileName! Passed

  1. IF聲明不得有DO子句。
  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 

右括號會導致您的問題一個問題,因爲它會關閉,如果子句和循環。
刪除他們或逃避他們

ECHO The following line(s^) !fileName! are ... corresponding line(s^) in ... 
+0

哇感謝捕捉! – jerryh91

+0

嘿,它仍然給我同樣的錯誤:!fileName!在這個時候意外? – jerryh91

+0

它一直在說回聲後的某些字符:if errorLnCount == 1 AND lnCorrect == false(echo!!fileName!中的以下行對於!testNum!中的相應行不正確)-Ref.properties.txt \t \t \t \t) – jerryh91