Passing an argument that contains an exclamation mark (!) to a groovy script from a Windows command line gets stripped away because Windows is trying to expand a variable name using delayed expansion (see this, this, and this). There are quite a few solutions posted that incorporate one of these solutions:
- setlocal ENABLEDELAYEDEXPANSION
- Escaping "with quotes^!"
- Escaping without quotes^^!
These are all accepted answers so apparently it works in some cases but it's NOT working for me. Here's the behavior I get on Windows 10 Professional:
C:\sof>type cmdtest.groovy
PASSWD=args[0]
println PASSWD
C:\sof>groovy cmdtest.groovy foopasswd!
foopasswd
C:\sof>groovy cmdtest.groovy foopasswd^^!
foopasswd
C:\sof>groovy cmdtest.groovy "foopasswd^!"
foopasswd
C:\sof>setlocal DisableDelayedExpansion
C:\sof>groovy cmdtest.groovy foopasswd!
foopasswd
C:\sof>groovy cmdtest.groovy foopasswd^^!
foopasswd
I figure it's somehow happening in the groovy.bat
so I also tried adding setlocal DisableDelayedExpansion
to groovy.bat
and it also didn't work.
Can somehow tell me the trick to make the above cmdtest.groovy
respect the !'s?