2012-07-06 102 views
8

cmd.exe一直给我一个当我运行下面的代码时,该命令的语法是不正确的错误。它出什么问题了?命令语法批量不正确?

代码:

@echo off 
setlocal enabledelayedexpansion 
CALL ant clean build compile 

REM loop thru/Run ALL .properties file names from "ExecutionSDKTest_10.2.2" folder 
:labelNextTest 
FOR %%G in (C:\ExecutionSDKTest_10.2.2\*.properties) DO (
    pause 
    Set fileName=%%~nxG 
    rem fileName==ENG-822.properties  
    set testName=!fileName:~0,7! 
    rem testName==ENG-822 
    set testNum=!fileName:~4,3! 
    REM testNum==822 
    ECHO Please Create: !testName!_Ref.properties.txt in C:\ExecutionSDKTest_10.2.2\Logs 
    echo Running:!fileName! 
    java -jar Test.jar !fileName! > Logs\!fileName!.log 

    set logPath="C:/ExecutionSDKTest_10.2.2/Logs/!fileName!.log" 
    set refLogPath="C:/ExecutionSDKTest_10.2.2/Logs/!testName!_Ref.properties.txt" 
    REM if Ref exists check Line by line 
    if EXIST !refLogPath!( 
     Call Perl TestProp1RefcheckLines.pl !fileName! !testName! 
) else (
    rem if ref does NOT exist check one important line 
    rem returns case number to check for 
    perl.exe c:\ExecutionSDKTest_10.2.2\TestProp1noRefCases.pl !testNum! 
    set lineCase=!ERRORLEVEL! 
    echo linecase is !lineCase! 

    rem set LineCase to one, two, three or four, depending on case number 
    FOR /F "tokens=*" %%B in (!logPath!) Do (
    set logLine=%%B 
rem check line >> : "...job status:..." 
if /i "!logLine:~11,33!"=="... STATUS REPORT: ...Job status:"( 
    if "!lineCase!" =="1"( 
      if /i "!logline:~32!" == "job status: job finished_error" goto labelPass 
      ) 
    if "!lineCase!"=="2" ( 
    if /i "!logLine:~32!" == "Job status: job QUEUED" goto labelPass 
      ) 
    if "!lineCase!"=="4"( 
    if /i "!logLine:~32!" == "job Execution Finished Successfully" goto labelPass 
    ) 
) else ( 
     if /i "!logLine:~11,33!"=="Error initializing the connection" goto labelPass 
    if /i "!logLine!" == "Exception in thread ""main"" java.lang.IllegalArgumentException: timeout value is negative" goto labelPass 
) 
) 
    goto labelFail 
    ) 
    ) 
pause 

REM Test Passed or Failed 
:labelFail 
echo !TestName! FAILED due to the above incorrect line 
goto labelNextTest 

:labelPass 
Echo !TestName! PASSED 
goto labelNextTest 
+2

最基本的问题是你最好把这个复杂的东西放在Perl脚本中。或者一个Powershell脚本或一个VBScript。甚至还有一个Ant任务。 *任何*但.bat文件。恕我直言... PS:你有什么想法是什么线它barfing? – paulsm4 2012-07-06 19:11:56

+1

欢迎来到BAT编程和调试的美妙世界。看到这个SO问题http://stackoverflow.com/questions/8987208/how-do-i-make-sense-of-a-batch-file/8987977#8987977 – 2012-07-06 19:16:45

回答

11

你错过了几个关键的空间。在这些线路:

if EXIST !refLogPath!(

if /i "!logLine:~11,33!"=="... STATUS REPORT: ...Job status:"( 

if "!lineCase!" =="1"( 

if "!lineCase!"=="4"( 

必须有放在括号(前的空间!

是的,批处理脚本很难调试。但实际上,脚本可能看起来更漂亮(正确缩进,等等)。