commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bernd Eckenfels <>
Subject Re: [cli] absolute file path parsing
Date Wed, 16 Aug 2017 08:20:59 GMT
If this is unix/Linux you cannot type \ on the command line without quoting, that's not related
to Java. You can double the backslash or put it in "quotes". If you expect more characters
which should not interpreted by the shell, use single quotes. CLI cannot work around this,
it simply does not get the character passed. Since this affects all Linux commands you won't
need to deal with this.

From: Roger Crerie <>
Sent: Tuesday, August 15, 2017 4:55:31 PM
Subject: [cli] absolute file path parsing

I am using the apache.commons.cli CommandLineParser and am running into the following problem.....

$ java -jar ./target/sorteria-0.0.1-SNAPSHOT-jar-with-dependencies.jar -f C:\shared\HCPAnywhere\AW001_3.0.0.20.iso
-t ISO
test = C:sharedHCPAnywhereAW001_3.0.0.20.iso
File = C:sharedHCPAnywhereAW001_3.0.0.20.iso

When getting the -f option which is going to be an absolute file path the parser removes the
\ character.  If I use \\ this works fine

$ java -jar ./target/sorteria-0.0.1-SNAPSHOT-jar-with-dependencies.jar -f C:\\shared\\HCPAnywhere\\AW001_3.0.0.20.iso
-t ISO
test = C:\shared\HCPAnywhere\AW001_3.0.0.20.iso
File = C:\shared\HCPAnywhere\AW001_3.0.0.20.iso

I don't want the end user of this tool to have to know to do this though.  Is there a way
for the parser to handle the \ character?  Maybe in the creation of the options?  What I have
for creating this option is....

Option file = new Option("f", "file", true, "Absolute File and Location");


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message