简体   繁体   中英

java program arguments from bat file

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 ?

%* is usually the simplest solution here. Eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM