Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing exclamation point to java program on command line

I want to pass the string "!changeme!" to a java program on the command line like:

java -cp "!AXIS2_CLASS_PATH!" ClientJava --userid admin --passwd "!changeme!"

Using Windows XP, Java jdk 1.6.0_07.

The AXIS2_CLASS_PATH gets replaced as normal, I assume by the java runtime. 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.

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:

Use the caret to escape the exclamation mark.

java -cp "!AXIS2_CLASS_PATH!" ClientJava --xxx "^!changeme^!"

arg: --userid
arg: admin
arg: --passwd
arg: !changeme!
like image 553
brofield Avatar asked Dec 05 '25 06:12

brofield


1 Answers

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"!""
like image 194
Zach Scrivena Avatar answered Dec 07 '25 20:12

Zach Scrivena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!