groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <pa...@asert.com.au>
Subject Re: Disguise groovy script as windows batch file
Date Wed, 03 Jun 2015 10:56:19 GMT

I think you need "@interface ECHO" not just "interface ECHO".

Cheers, Paul.

On 3/06/2015 8:05 PM, Maarten Boekhold wrote:
> Hi all,
>
> Based on http://snipplr.com/view/70875
>
> The following works with groovy 2.1.8, but fails with 2.3.7 or 2.4.3:
>
>     @ECHO OFF
>     REM = /
>     REM dummy groovy statement in first line and dummy groovy assignment to dummy string
var rem
>     SET _JAVA_OPTIONS=
>     SET CLASSPATH=
>     C:\Maarten\local\groovy-2.1.8\bin\groovy "%~dp0%~nx0" %*
>     GOTO :EOF
>     /
>     interface ECHO {}
>     // dummy groovy interface/annotation to make groovy interpreter ignore first line
>     // start of script
>
>     println "### Hello World from Groovy"
>     System.exit(0)
>
> When I run this with groovy 2.3.7 or 2.4.3, I get:
>
>     org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
>     C:\Maarten\tg.bat: 1: class ECHO is not an annotation in @ECHO
>       @ line 1, column 1.
>         @ECHO OFF
>         ^
>
>     1 error
>
> Is there any way to make this work on recent versions of Groovy? The idea here is to
have a groovy script that I can launch directly from a CMD prompt without needing to have
groovy in the path, type "groovy thescript.groovy" or using a wrapper .bat file.
>
> The definition of "interface ECHO {}" is there to make groovy ignore the first line of
the file, by tricking it into thinking it is an annotation on the assignment to the REM variable.
>
> Maarten


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


Mime
View raw message