-1

i've a java application that takes 2 parameters and i want to make batch file .bat to run the jar file i want to pass the parameters to the jar file using the echo command so if i clicked on the .bat file then a message telling

please enter the first parameter

after pressing enter another message appears

please enter the second parameter

at the end these 2 parameters will be passed to the jar file

java -jar MathCalculations.jar firstParameter seconedParameter

any recommendations how to write this batch file please?

Mahmoud Ismail
  • 187
  • 1
  • 3
  • 12

1 Answers1

1

The simple solution:

@echo off
set /P "Parameter1=Please enter first parameter: "
set /P "Parameter2=Please enter second parameter: "
java.exe -jar MathCalculations.jar "%Parameter1%" "%Parameter2%"

Enter in a command prompt window either set /? or help set for more information.

Please note that the user of the batch file can just hit ENTER or RETURN without entering anything. You may define default values for this case like

@echo off
set "Parameter1=Default Option 1"
set /P "Parameter1=Please enter first parameter: "
set "Parameter2=Default Option 2"
set /P "Parameter2=Please enter second parameter: "
java.exe -jar MathCalculations.jar "%Parameter1%" "%Parameter2%"
Mofi
  • 46,139
  • 17
  • 80
  • 143