Redirecting passed arguments to a windows batch file

62,010

Does

java -jar foo.jar %*

meet your needs? It should add all parameters from the batch execution to your application call within the batch file.

Share:
62,010
Krishna Gopalakrishnan
Author by

Krishna Gopalakrishnan

Loves technology, coding. Googler.

Updated on September 24, 2020

Comments

  • Krishna Gopalakrishnan
    Krishna Gopalakrishnan almost 4 years

    I would like to call a jar file from a windows batch file. One requirement is to be able to pass all the batch file arguments as-is to the jar file invocation. For example,

    Required Command line:

    foo.bat --flag1=x --flag2=y --flag3=z
    

    The batch file foo.bat should invoke foo.jar like follows:

    java -jar foo.jar --flag1=x --flag2=y --flag3=z
    

    How do I make the batch file do this?
    I can do some batch variable magic with % to do this, but is there a simpler way to do this?

  • Barney Szabolcs
    Barney Szabolcs about 8 years
    This does not preserve the quotations. :'(
  • Speedstone
    Speedstone almost 6 years
    I think I found a solution that works with parameters in quotations: serverfault.com/a/22541
  • Sam
    Sam almost 5 years
    This worked perfectly for me on Windows 10 1903, including preserving double-quotes around arguments.
  • Erhannis
    Erhannis almost 3 years
    @Sam "This" being the original answer, or Speedstone's link?
  • mh166
    mh166 over 2 years
    @Erhannis For me, it is the original answer. It kept the quotation marks where they belonged. :)