tags:

views:

38

answers:

2

Hi,

I tried to invoke java inside bash script on windows (Win XP) using cygwin. However path to java.exe contain spaces.

only literaly putting in bash sometghing like this worked:

/cygdrive/c/Program\ Files/Java/jdk1.5.0_10/bin/java -cp "$TOOL_HOME" DateParse  "$DATE" "$FORMAT"

My attemts to put java path to a variable failed:

export JAVA_EXE="/cygdrive/c/Program\ Files/Java/jdk1.5.0_10/bin/java"
$JAVA_EXE -cp "$TOOL_HOME" DateParse  "$DATE" "$FORMAT"

also different combination with cygpath, quotes, brackets did not work. I am not finding the the right combination

A: 

Put quotes around $JAVA_EXE:

"$JAVA_EXE" -cp "$TOOL_HOME" DateParse  "$DATE" "$FORMAT"

The problem is that every time a variable is expanded, its also broken into words at spaces, UNLESS you put quotes around it. So if you don't want things broken at spaces, you need quotes.

Another alternative is to always use short (DOS) names for things, which don't allow spaces. To see what the short name is, run

cygpath -d "$JAVA_EXE"

to convert that back to a unix-like cygwin path, use

cygpath -u $(cygpath -d "$JAVA_EXE")
Chris Dodd
A: 

Hello,

thank you for your ideas. It worked in proper combination. The issue was that I was escaping space character and at the same time putting JAVA_EXE in quotes.

export JAVA_EXE="/cygdrive/c/Program Files/Java/jdk1.5.0_10/bin/java"
"$JAVA_EXE" -cp "$TOOL_HOME" DateParse  "$DATE" "$FORMAT"

produce this effect:

line 30: /cygdrive/c/Program\ Files/Java/jdk1.5.0_10/bin/java: No such file or directory

on the other hand, converting to DOS 8.3 does not work neither:

cannot create short name of \\?\C:\Program\ Files\Java\jdk1.5.0_10

\bin\java

Finally, putting JAVA_EXE in quotes but without escaping space in path worked fine for me:

export JAVA_EXE="/cygdrive/c/Program Files/Java/jdk1.5.0_10/bin/java"

"$JAVA_EXE" -cp "$TOOL_HOME" DateParse  "$DATE" "$FORMAT"
Boris