I was a bit surprised that the problem handling * in arguments in Windows still exists in groovy-1.6.0. So I spend some time with the stargGroovy.bat script to find a solution for this. As discussed above, the problem is cause by the FOR loop in the "horrible script".
I identified two problems with this:
1. Before the FOR loop is executed, some but NOT ALL existing * characters are escaped.
2. The processing of the command line will split the line by spaces IGNORING any existing quotation.
Please note: The second point is also responsible that groovy will fail if it is installed in directories having a space in the path, as the groovy path is the first argument of the FOR loop.
A solution to item 1 can be provided by a simple enhancement of the existing script. See the attached file V1 for the details. It will collect arguments starting with a quote until the closing quote appears. As there are only minimal changes of the existing script, it is very unlikly that this change will have any unexpected side effects.
But this fix will still not handle the problem with the * character. To find a solution for this, I tried to understand why the FOR loop is used at all. The loop is labeled ":win9xME_args_slurp", which seems to indicate a backward compatibility for old win9x systems is provided. I checked with an win98SE system installed in a virtual box and was quite surprised: Before winNT the command shell from windows did not know anything about the %~ operators. That will mean that ALL of your batch files will fail on a windows version before NT. For this I don't see any need to keep the backward compatibility here in place. But winNT does provide a simple method to collect the command line arguments in a batch file. This will allow to remove most of the horrible parts of the script and avoids the FOR loop at all. So please find the NT based solution in the attached file V2. (Note: As the command line handling is really simple now, I have removed the special handling for the 4NT systems, specially as
GROOVY-1925 is indicating that the current solution did not even work.)
I have tested my solutions on a W2K and Vista64 system and worked fine. Spaces in the path are no longer a problem and spaces in arguments are handled correctly. Globbing is only done if a * appears outside of quotes, a * inside of quotes is passed unchanged to the script. Even escaping quotes will work, as shown here:
-> groovy -e "println \"$args\"" arg1 arg2 "a r g 3" "*"