Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.6
-
Fix Version/s: 2.1.0-rc-2, 2.1.0, 2.0.7
-
Component/s: command line processing
-
Labels:None
-
Environment:MS Windows XP
-
Number of attachments :
Description
Here it is:
$ groovy -version
Groovy Version: 1.6.0 JVM: 1.6.0_12
I have the following script that I put in my $HOME/bin on cygwin, where $HOME maps to regular Windows home: C:\Documents and Settings[my_username]
[my_username] ~/bin
$ cat test.groovy
def f = new File(args[0])
println f.listFiles()
Now I try to run it from c:
[my_username] /cygdrive/c
$ groovy /cygdrive/c/Documents\ and\ Settings/[my_username]/bin/test.groovy .
/cygdrive/c/Program Files/Groovy/Groovy-1.6.0/bin/startGroovy: line 227: and: command not found
Caught: java.lang.IllegalArgumentException: C:\ (C:) is a directory not a Groovy source file.
I do think this is a bug in startGroovy script.
I am currently testing out this patch in my cygwin environment, so far so good:
% diff -u startGroovy.DIST startGroovy
— startGroovy.DIST 2009-07-07 22:40:47.140625000 -0500
+++ startGroovy 2009-07-07 23:53:42.828125000 -0500
@@ -218,10 +218,9 @@
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
if [ $CHECK -ne 0 ] ; then
+ arg=`cygpath --path --ignore --mixed "$arg"`
fi
+ eval `echo args$i`=\'"`echo "x$arg" | sed -e "s/^x//" -e "s,','\\\\\'',g"`"\'
i=`expr $i + 1`
done
case $i in
There is a more elegant substitution in bash but since the script appears to be avoid such usage I changed it to the scary looking echo|sed
{arg//\'/$s}s="'\''"; # a quoted single quote
eval `echo args$i`="'$
'"
My testcase in cygwin:
% groovy -e 'println System.getenv("""JAVA_HOME"""); println args[0]' '/bin/foo"'\'' "bar'
c:/Program Files/Java/jdk1.5.0_18
C:/cygwin/bin/foo"' "bar
This results in much safer argument munging than the current script uses. Personally I would go in and double-quote all the variable expansions that aren't quoted currently as well.