You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Maarten Boekhold <bo...@gmx.com> on 2015/06/03 12:05:13 UTC

Disguise groovy script as windows batch file

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

Re: Disguise groovy script as windows batch file

Posted by Maarten Boekhold <bo...@gmx.com>.
Awesome, thanks Paul, that's working!

On 2015-06-03 14:56, Paul King wrote:
>
> 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
>


Re: Disguise groovy script as windows batch file

Posted by Paul King <pa...@asert.com.au>.
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