Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EBC1F1771C for ; Wed, 3 Jun 2015 10:05:26 +0000 (UTC) Received: (qmail 52993 invoked by uid 500); 3 Jun 2015 10:05:26 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 52951 invoked by uid 500); 3 Jun 2015 10:05:26 -0000 Mailing-List: contact users-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.incubator.apache.org Delivered-To: mailing list users@groovy.incubator.apache.org Received: (qmail 52941 invoked by uid 99); 3 Jun 2015 10:05:26 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Jun 2015 10:05:26 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 1606BC0729 for ; Wed, 3 Jun 2015 10:05:26 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3 X-Spam-Level: *** X-Spam-Status: No, score=3 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 9oNgxdRM9SBw for ; Wed, 3 Jun 2015 10:05:17 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 3FE62275E3 for ; Wed, 3 Jun 2015 10:05:17 +0000 (UTC) Received: from [10.17.0.165] ([94.56.107.152]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0M3i8r-1ZHkt804uX-00rID3 for ; Wed, 03 Jun 2015 12:05:15 +0200 Message-ID: <556ED159.3090007@gmx.com> Date: Wed, 03 Jun 2015 14:05:13 +0400 From: Maarten Boekhold User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: users@groovy.incubator.apache.org Subject: Disguise groovy script as windows batch file Content-Type: multipart/alternative; boundary="------------050601020903010901090803" X-Provags-ID: V03:K0:7l1dSsKcFJLF/pHSieilwTz+O1ofs5rGj8HCjoEzhflHqzDH0QQ ax/oURGq2o2wU4rr3OqrdakX3cyK1pBUvl5tuWZFIl1cJk8tkJ9WjXrzeIsNqZmA7dAM2Db mLsRWiQ9TWXIT3D5tYasYijv7Z1HOv/iY9x+j8XjjeCYzUy6n3KTnDj4CFlvKLTjVDDQEIK YVEEWxfRtoD+uMKqT5MSw== X-UI-Out-Filterresults: notjunk:1; This is a multi-part message in MIME format. --------------050601020903010901090803 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------050601020903010901090803 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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
--------------050601020903010901090803--