Syantx of command of wrong when we ran with single arument

When I ran the below script with single/Without  arguments
Ex.AB-A0123-DLY
  AB-A0123-DLY 4

it was giving the error as The syntax of the command is incorrect was wrong.
@echo off
cls
setlocal EnableDelayedExpansion

SET arg1=%1
call %~dp0\ABMaster.bat

::#Get the number of arguments
SET /A ARGS_COUNT=0
FOR %%A in (%*) DO SET /A ARGS_COUNT+=1 

::#Calculate thread count,thread start and thread end numbers only all three arguments are supplied.
IF "%3" == "" GOTO cont
SET /A a = %1%
SET /A b = %2%
SET /A c = %3%
:cont

IF %ARGS_COUNT% == 2 GOTO MIN_ARG
IF %ARGS_COUNT% geq 4 (
      :MIN_ARG      
            echo Incorrect arguments provided. Ending the job. Run the job with  correct arguments as shown in below example. 
            set ERRORLEVEL=-1 
            GOTO JOB_STATUS
      )
IF %ARGS_COUNT% leq 1  (
      IF "%arg1%" == "" (
            @echo Executing job without Parameters
            Java %JAVA_OPTS% -Djava.awt.headless=true -server -Xms1024m -Xmx2048m -XX:MaxPermSize=512m -XX:NewSize=64m -XX:MaxNewSize=64m -XX:NewRatio=3 com.abc.abcDriver AB-A0123-DLY >%BATCH_LOG%\AB-A0123-DLY_%timestamp%.txt 2>&1
      ) ELSE (
            @echo Executing job with single Parameters
            FOR /L %%G IN (1,1,%arg1%) DO (
                  @echo Executing job with Parameter %%G
                  cmd /c start /b %~dp0TestParallelRun.bat AB-A0123-DLY %%G %arg1%
                  ping -n 6 127.0.0.1 >nul
            )
      )

      :checkfile
      FOR /L %%G IN (1,1,%arg1%) DO (
            if not exist %BATCH_LOG%\AB-A0123-DLY_T_%%G_%arg1%.txt GOTO checkfile
            )
      FOR /L %%G IN (1,1,%arg1%) DO (
            set /p value=< %BATCH_LOG%\AB-A0123-DLY_T_%%G_%arg1%.txt
            SET trimval=!value: =!
            IF NOT !trimval! == 0 (
                  set ERRORLEVEL=!trimval!
                  del %BATCH_LOG%\CO\AB-A0123-DLY_T_*.txt
                  GOTO JOB_STATUS
            )
      )
)

IF "%ARGS_COUNT%" == "3" (
	FOR /L %%G IN (%b%,1,%a%) DO (			
		@echo Executing job with Parameter %%G
		cmd /c start /b %~dp0TestParallelRun.bat AB-A0123-DLY %%G %a%
		ping -n 6 127.0.0.1 >nul
		
		IF %%G geq %c% (			
			goto :BREAK
		)
	)
	:checkfile2
	FOR /L %%G IN (%b%,1,%a%) DO (
		if not exist %BATCH_LOG%\AB-A0123-DLY_T_%%G_%a%.txt GOTO checkfile2
		IF %%G geq %c% (			
			goto :checkfile3
		)
	)
	:checkfile3
	FOR /L %%G IN (%b%,1,%a%) DO (
		set /p value=< %BATCH_LOG%\AB-A0123-DLY_T_%%G_%a%.txt
		SET trimval=!value: =!
		IF NOT !trimval! == 0 (
			set ERRORLEVEL=!trimval!
			del %BATCH_LOG%\AB-A0123-DLY_T_*.txt
			GOTO JOB_STATUS
		)
		IF %%G geq %c% (			
			goto :BREAK
		)
	)
)

:BREAK
if exist %BATCH_LOG_TRUNK%\AB-A0123-DLY_T_*.txt del %BATCH_LOG_TRUNK%\AB-A0123-DLY_T_*.txt

:JOB_STATUS
call %~dp0\ABCJobStatus.bat

Open in new window

kumar sivaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
The syntax error with no parms is caused by these statements:

     FOR /L %%G IN (1,1,%arg1%) DO (

since %arg1% is blank (undefined) when no parms are passed.  I don't know how you want the logic to work with no parms, but you will have to code for this case.  As it stands it generates a FOR /L %%G in (1 1) DO which is an invlaid statement since there need to be three numbers inside the parens.

I tried the script with one parameter here and it worked okay, continuously looping waiting for a file to be created...

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kumar sivaAuthor Commented:
With three arguments it was working fine
Ex:AB-A0123-DLY  5 5 15  and batch was ended successfully with zero  return code as shown in below.
Batch Job succeeded with error leve = 0 l
ABCJobStatus.bat code as shown in below
set errlvl=%ERRORLEVEL%

IF %errlvl% ==-99 (
echo Batch Job Aborted with error level = %errlvl% 
)

IF %errlvl%==0 (
echo Batch Job succeeded with error level = %errlvl% 
)

IF %errlvl%==-1 (
echo Batch ended but not succeeded because it's return error code = %errlvl% 
)
IF %errlvl%==4 (
echo FT Batch is not succeeded because it's return error code = %errlvl% 
)
IF %errlvl%==5 (
echo Batch is not succeeded because it's return error code = %errlvl% 
)
set RESEXE=%errlvl%

Open in new window


It was failing with single and without arguments as explained in the above
0
Bill PrewCommented:
Did you understand the problem I identified, and did it resolve your problem?

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.