0

I've got a Java program that takes parameters such as "-range=1-5 -message=Hello".

I've a written a .bat file to launch that java program with a specific jre and some preset parameters. I would like to be able to launch the .bat file with some extra parameters to be added to the java program.

the myexe.bat file is

echo on
rem Force 32 bit Java 
"C:\Program Files (x86)\Java\jdk1.8.0_162\bin\java.exe" -jar myexe.jar -param1="value1"  %1 %2 %3 %4 %5 %6 %7 %8 %9

I'm expecting that calling

myexe.bat -param2=value2

would lead to

.. -jar myexe.jar -param1="value1" -param2=value2

Instead it's leading to

.. -jar myexe.jar -param1="value1" -param2 value2

Which is wrongly interpreted by the java program.

Surrounding by quotes such as in .. -jar myexe.jar -param1="value1" "-param2=value2"

Instead it's leading to

.. -jar myexe.jar -param1="value1" "-param2=value2"

Which is also wrongly interpreted by the java program.

Is there a way in the .bat file to use its arguments exactly as they were set ?

3
  • "Which is also wrongly interpreted by the java program." Care to say how/why do you think so? Commented Mar 8, 2018 at 22:00
  • Either way, I remember windows didn't work well with foo="bar" syntax. You need to consistently enquote the whole parameter. Commented Mar 8, 2018 at 22:01
  • The program is looking for some value after the param2. It doesn't find anything. So it complains. It's also considering value2 as parameter and says it is no valid parameter. Anyway df778899 solution is perfect ! Commented Mar 9, 2018 at 21:31

1 Answer 1

2

%* is usually the simplest solution here. E.g. this batch file:

echo %1 %2 %3
echo %*

Produces this output:

>mybat.bat -param2=value2

>echo -param2 value2
-param2 value2

>echo -param2=value2
-param2=value2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.