How to pass two arguments while calling jar file in batch script?

Following is my batch script

@echo off

set /a java_output=43350674
set /a img_id=1

setlocal enableDelayedExpansion

:top

for /f "tokens=1-2 delims= " %%A in ( 'java -jar test.jar %java_output%,%img_id%' ) do (
    set /a java_output=%%A
    set /a img_id=%%B
)

echo %java_output%
SET /A "err=error"
if "%java_output%" EQU "%err%" (
    echo %img_id% > batch_log.txt
    echo "End of batch script"
    exit /b %ERRORLEVEL%
) else (
    if %java_output% LSS 43350681 ( 
        goto top 
    )
)
endlocal

Getting expected output but I am getting “Missing operand” error each time the for loops runs.

Error in " set /a img_id=%%B " 

I have doubt in this line for /f "tokens=1-2 delims= " %%A in ( 'java -jar test.jar %java_output%,%img_id%' ) do (

Is this the correct way to pass 2 batch variables to jar file ?

Following is my java code in jar file.

public class Test {

    public static void main(String[] args) 
       {
        System.out.println(args[0]);
        int ret = Integer.parseInt(args[0]);
        // for error scenarios
        String err = "error";
        if(ret == 43350677)
        { 
            System.out.println(err+" "+ret);
        }
        else
        {
            System.out.println(ret+1+" "+ret);
        }
       }
}

Following is my output :

C:>test.bat
Missing operand.
43350675
Missing operand.
43350676
Missing operand.
43350677
Missing operand.
0
"End of batch script"

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

If you want to start a jar file together with parameters out of a Windows script use the following syntax:

call java -jar my-jar-file.jar parm1 parm2 ...

The call is essential, otherwise the parameters are ignored.