[英]Passing exclamation point to java program on command line
I want to pass the string "!changeme!" 我想传递字符串“!changeme!”。 to a java program on the command line like:
到命令行上的Java程序,例如:
java -cp "!AXIS2_CLASS_PATH!" ClientJava --userid admin --passwd "!changeme!"
Using Windows XP, Java jdk 1.6.0_07. 使用Windows XP,Java jdk 1.6.0_07。
The AXIS2_CLASS_PATH gets replaced as normal, I assume by the java runtime. 我假设Java运行时将AXIS2_CLASS_PATH正常替换。 However the password of !changeme!
但是,密码为! also seems to be replaced with an empty string.
似乎也被替换为空字符串。 I assume that this replacement is some sort of JVM feature.
我假设这种替换是某种JVM功能。
Using the following program: 使用以下程序:
static int Run(String[] aArgs) {
for (String s: aArgs) {
System.out.println("arg: " + s);
}
return 0;
}
I get the following results: 我得到以下结果:
"C:\Program Files\Java\jdk1.6.0_07\bin\java" -cp "!AXIS2_CLASS_PATH!"
ClientJava --userid admin --passwd "!changeme!"
arg: --userid
arg: admin
arg: --passwd
arg:
I need the password to be passed through as is. 我需要原样通过密码。 I've tried all sorts of escaping but I haven't found what I need to use.
我已经尝试了各种转义,但没有找到需要使用的东西。
Can anyone supply a hint on how to do this? 谁能提供有关此操作的提示?
Solution as provided by Zach Scrivena is: Zach Scrivena提供的解决方案是:
Use the caret to escape the exclamation mark. 使用插入符号可避免出现感叹号。
java -cp "!AXIS2_CLASS_PATH!" ClientJava --xxx "^!changeme^!"
arg: --userid
arg: admin
arg: --passwd
arg: !changeme!
The problem is caused by the command-line interpreter --- it's replacing the term enclosed in exclamation marks !
问题是由命令行解释器引起的,它代替了感叹号中的术语
!
with the corresponding environment variable. 与相应的环境变量。
Simply precede each escaped character by a caret ^
. 只需在每个转义字符的前面加上插入符号
^
。 This works for both the command-line and batch files: 这适用于命令行和批处理文件:
java -cp "!AXIS2_CLASS_PATH!" ClientJava --xxx "^!changeme^!"
On the command-line, you can also enclose each escaped character in double quotes "
在命令行上,您还可以将每个转义的字符括在双引号
"
java -cp "!AXIS2_CLASS_PATH!" ClientJava --xxx ""!"changeme"!""
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.