英文:
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 "".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论