The following comment has been added to this issue:

     Author: Ronald Blaschke
    Created: Sun, 18 Apr 2004 11:45 AM
       Body:
A batch file is executed via a cmd.exe command shell, either the 
current one or a new one.  When Ant's <exec ... failonerror="true">
is used, a new shell is spawned which executes the batch file.
As usual, the process exit code is used to determine if the shell
returned successfully (==0) or failed (!=0).

Now, the problem is the shell's exit code.  As far as I can tell,
it's either the result of the last call in the batch file, or
the value explicitly set via the "EXIT" call.  For example, the
following batch file, when executed via <exec>, fails as it should.

--- build.xml
    ...
    <exec executable="some.bat" failonerror="true"/>
    ...
--- some.bat
@echo off

java SomeMissingClass
---
C:\temp>ant
Buildfile: build.xml

all:
     [exec] java.lang.NoClassDefFoundError: SomeMissingClass
     [exec] Exception in thread "main"


BUILD FAILED
C:\temp\build.xml:4: exec returned: 1
---

Unfortunately, as soon as you add other commands the
status gets lost (at least _some_ commands, eg
SET does not harm the status).

--- some.bat
@echo off

java SomeMissingClass

goto end

:end
---
     [exec] java.lang.NoClassDefFoundError: SomeMissingClass
     [exec] Exception in thread "main"

BUILD SUCCESSFUL
---

Windows also sets a pseudo-environment variable ERRORLEVEL to
the exit status of the last executed process, in the example
above to the exit status of "java," which would be the one
we want.

--- some.bat
@echo off

java SomeMissingClass

goto end

:end

exit %ERRORLEVEL%
---
     [exec] java.lang.NoClassDefFoundError: SomeMissingClass
     [exec] Exception in thread "main"


BUILD FAILED
---

But if the batch file is called by an existing shell (command line), 
it is executed _in_ that shell, and the exit call would end it, not
just the batch file.

One could explicitly spawn the shell, call the batch file, and end
it with EXIT.

--- build.xml
    <exec executable="cmd.exe" failonerror="true">
      <arg value="/c"/>
      <arg value="call some.bat; EXIT %ERRORLEVEL%"/>
    </exec>
---

Note the "/c" and the "call" before some.bat.

---------------------------------------------------------------------
View this comment:
  
http://jira.codehaus.org/secure/ViewIssue.jspa?key=MAVEN-1124&page=comments#action_18759

---------------------------------------------------------------------
View the issue:
  http://jira.codehaus.org/secure/ViewIssue.jspa?key=MAVEN-1124

Here is an overview of the issue:
---------------------------------------------------------------------
        Key: MAVEN-1124
    Summary: Add exit to maven.bat
       Type: Improvement

     Status: Closed
   Priority: Trivial
 Resolution: WON'T FIX

 Original Estimate: 1 minute
 Time Spent: Unknown
  Remaining: 1 minute

    Project: maven
 Components: 
             core
   Fix Fors:
             1.0-rc3

   Assignee: 
   Reporter: Ronald Blaschke

    Created: Thu, 22 Jan 2004 5:59 AM
    Updated: Sun, 18 Apr 2004 11:45 AM
Environment: Windows (XP)

Description:
Windows (XP) seems to not propagate the last ERRORLEVEL in batch files.  Thus, when 
calling maven.bat from an ant build file, ant reports success, even when maven fails.

...
1 error
2 warnings
BUILD FAILED

Total time: 6 seconds
Finished at: Thu Jan 22 11:49:10 CET 2004

File...... file:/C:/Documents and Settings/user/.maven/plugins/maven-test-plugin-1
.4/
Element... javac
Line...... 34
Column.... 46
Compile failed; see the compiler error output for details.



BUILD SUCCESSFUL
Total time: 8 seconds


---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.

If you think it was sent incorrectly contact one of the administrators:
   http://jira.codehaus.org/secure/Administrators.jspa

If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to