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.
Gruss Bernd -- http://bernd.eckenfels.net ________________________________ From: Roger Crerie <[email protected]> Sent: Tuesday, August 15, 2017 4:55:31 PM To: [email protected] 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"); file.setRequired(true); options.addOption(file); Roger [email protected]
