With a little side of applesauce...

Thursday, April 10, 2008

Java command-line arguments

Aahhhhh!! The heavens have opened... :P So the Java command-line delimiter is whitespace, as per:
http://books.google.com/books?id=_NSqe1MOI7IC&pg=PA120&lpg=PA120&dq=java+%22command+line%22+arguments+delimiter&source=web&ots=XhdZUEDH89&sig=6_5J0bdOGLg8Lwq0JTsyVbrBazM&hl=en

That isn't a big surprise. BUT, when I am using a shell script to call /usr/bin/java, the command-line args with double or single quotes are split into:

u '"/home/myuser/Mail/Sent' 'Items"'


Sorry, Java!! I was bad-mouthing you the whole time :P

The fix was alluded to the the FAQ at:
http://tiswww.case.edu/php/chet/bash/FAQ Section E14

Assign the value to a SHELL variable, then quote it in the string passed to Java interpreter. ie:

MYARG=$4
java MyClass arg1 arg2 arg3 "${MYARG}"

No comments: