groovy
  1. groovy
  2. GROOVY-1034

running groovy.bat does not return exit status on windows

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0-JSR-3
    • Fix Version/s: 1.7.2, 1.6.9, 1.8-beta-1
    • Component/s: None
    • Labels:
      None
    • Environment:
      win xp sp2, java 1.4.2_09
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      Running groovy from within another script does not give the real exit value of the groovy process. Try any of the following:

      perl -e "system('groovy -e \"System.exit(1)\"');print $?>>8"
      ruby -e "system('groovy.bat -e \"System.exit(1)\"');print $?>>8"
      groovy -e "p='groovy.bat -e \"System.exit(1)\"'.execute();p.waitFor();println p.exitValue()"

      To see that the above examples are correct in catching the exit code, try e.g.

      ruby -e "system('ruby -e \"exit(2)\"');print $?>>8"
      groovy -e "def p='ruby -e \"exit(2)\"'.execute();;p.waitFor();println p.exitValue()"

      Adding

      exit %ERROR_LEVEL%

      to the end of groovy.bat solves the problem but is not usable as it causes command prompt to exit if running groovy directly (i.e. not via some other script).

        Activity

        Hide
        blackdrag blackdrag added a comment -

        as last line you mean inclusive the CMD /C? that could prevent one or two problems if the bat file is called with command.com instead of cmd.exe

        Show
        blackdrag blackdrag added a comment - as last line you mean inclusive the CMD /C? that could prevent one or two problems if the bat file is called with command.com instead of cmd.exe
        Hide
        Tom Huybrechts added a comment -

        Yes, the full line, including CMD /C.

        In 1.5.7, the same problem existed, but you could fix it by adding this line to only groovy.bat.

        In Maven, the 'CMD /C' was added in MNG-3651. Not sure what problem it fixes.

        And for command.com, I hadn't heard about that since my Win98 days

        Show
        Tom Huybrechts added a comment - Yes, the full line, including CMD /C. In 1.5.7, the same problem existed, but you could fix it by adding this line to only groovy.bat. In Maven, the 'CMD /C' was added in MNG-3651 . Not sure what problem it fixes. And for command.com, I hadn't heard about that since my Win98 days
        Hide
        Philip Jenvey added a comment -

        For portability you can do %COMSPEC% /c instead of CMD /c (this is what we've done for jython.bat)

        Show
        Philip Jenvey added a comment - For portability you can do %COMSPEC% /c instead of CMD /c (this is what we've done for jython.bat)
        Hide
        Artem Petakov added a comment -

        Sorry, very new to this project. Any reason not to submit a patch for this? I am running 1.8.0 and still have the problem – I added this to my gant.bat and startGroovy.bat scripts as suggested and this fixed it.

        @rem Fix the problem that Gant does not return correct error code as documented in
        @rem http://jira.codehaus.org/browse/GROOVY-1034
        cmd /C exit /B %ERRORLEVEL%

        Show
        Artem Petakov added a comment - Sorry, very new to this project. Any reason not to submit a patch for this? I am running 1.8.0 and still have the problem – I added this to my gant.bat and startGroovy.bat scripts as suggested and this fixed it. @rem Fix the problem that Gant does not return correct error code as documented in @rem http://jira.codehaus.org/browse/GROOVY-1034 cmd /C exit /B %ERRORLEVEL%
        Hide
        Paul King added a comment -

        I added the following to all .bat files and it seemed to work for me in various tests:
        %COMSPEC% /C exit /B %ERRORLEVEL%

        Show
        Paul King added a comment - I added the following to all .bat files and it seemed to work for me in various tests: %COMSPEC% /C exit /B %ERRORLEVEL%

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Antti Karanta
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: