1

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?

3
  • 3
    I think you can pass arguments with %*: "%JAVA_HOME%\bin\java" -cp "/some.jar;other.jar" other.Main %* Commented Jan 31, 2013 at 19:58
  • 1
    You are correct. Simple enough. Add it as an answer, I'll accept. Maybe with explanation for others. Commented Jan 31, 2013 at 19:59
  • 1
    %* expands to all parameters, I believe Commented Jan 31, 2013 at 19:59

1 Answer 1

2

%* holds all arguments passed to a script.

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.