如何在Java的JAR参数中传递 `&` 符号?

huangapple go评论178阅读模式
英文:

How to pass & in java jar parameters?

问题

当我将 "&" 用作参数时,命令行会将 & 视为新命令的开头,但 & 实际上是我的参数的一部分。例如,如果我运行 java -jar Runner.jar ABC&DEF

我希望参数值为 "ABC&DEF",但我收到以下错误:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
        at Runner.main(Runner.java:11)

'DEF' 被视为内部命令、外部命令、可操作的程序或批处理文件的内容。

英文:

When I use "&" as parameters, the command line treats & as beginning of new command but & is a part of my argument. For eg- If I run java -jar Runner.jar ABC&DEF.

I want parameter value as "ABC&DEF" but I get error as below :

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
        at Runner.main(Runner.java:11)

'DEF' is not recognized as an internal or external command,
operable program or batch file.

答案1

得分: 5

你可以尝试用 ''"" 对参数进行引用。

英文:

You could try quoting the argument with '' or "".

huangapple
  • 本文由 发表于 2020年8月20日 01:25:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/63492069.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定