将传递的参数重定向到 Windows 批处理文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/980331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:28:39  来源:igfitidea点击:

Redirecting passed arguments to a windows batch file

windowsbatch-filearguments

提问by Krishna Gopalakrishnan

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,

我想从 Windows 批处理文件中调用 jar 文件。一项要求是能够将所有批处理文件参数按原样传递给 jar 文件调用。例如,

Required Command line:

所需的命令行:

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

The batch file foo.batshould invoke foo.jarlike follows:

批处理文件foo.batfoo.jar如下调用:

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?

如何使批处理文件执行此操作?
我可以用 % 做一些批处理变量魔术来做到这一点,但有没有更简单的方法来做到这一点?

回答by tschaible

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.

满足您的需求?它应该将批处理执行中的所有参数添加到批处理文件中的应用程序调用中。