Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax of the command is incorrect in batch?

The cmd.exe keeps giving me a The syntax of the command is incorrect error when I run the following codes. Whats wrong with it?

code:

 @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
like image 545
jerryh91 Avatar asked Jul 06 '12 19:07

jerryh91


People also ask

How do you fix the syntax of the command is incorrect?

This error message is generated when the Windows command line does not understand the syntax of the command because it is not formatted properly. To resolve this issue, surround any file name or directory name with spaces in it with quotes.

What is %% A in batch?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

What does 0 |% 0 Do in batch?

What does 0 |% 0 Do in batch? %0|%0 is a fork bomb. It will spawn another process using a pipe | which runs a copy of the same program asynchronously. This hogs the CPU and memory, slowing down the system to a near-halt (or even crash the system).

What is %% K in batch file?

So %%k refers to the value of the 3rd token, which is what is returned.


1 Answers

You're missing a few crucial spaces. In these lines:

if EXIST !refLogPath!(

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

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

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

there must be a space placed before the parenthesis ( !

Yes, batch scripts are very hard to debug. But really, the script could look prettier (indented properly, etc...).

like image 57
Eitan T Avatar answered Oct 19 '22 11:10

Eitan T