Sotirios Delimanolis Sotirios Delimanolis - 1 year ago 102
Java Question

Running Java program from Batch script with correct number of arguments

I have a java program can take a variable amount of parameters. Something like:

package other;
public class Main {
public static void main (String[] args) {
for (String arg: args) {/* do something */}

I want to run this java program from a .bat script.

"%JAVA_HOME%\bin\java" -cp "/some.jar;other.jar" other.Main %1 %2 %3

With this I can call my .bat script like

> myscript.bat arg1 arg2 arg3

This works if I have 3 arguments, but there can be a variable amount of arguments passed. How can I pass them all to the java program?

Answer Source

%* holds all arguments passed to a script.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download