[英]return exit code from ant to a batch file
I have several ant tasks in my .bat file to execute. 我的.bat文件中有几个蚂蚁任务要执行。
My .bat file is like below: 我的.bat文件如下所示:
call ant -buildfile task.xml target1
调用ant -buildfile task.xml target1
call ant -buildfile task.xml target2调用ant -buildfile task.xml target2
For each ant task, it will execute a java program and the program will return an exit code by using System.exit() . 对于每个ant任务,它将执行一个Java程序,并且该程序将通过使用System.exit()返回退出代码。
I know the exit code can be received by using resultproperty in ant configuration. 我知道可以通过在ant配置中使用resultproperty来接收退出代码。
How can I get the exit code in my .bat file from calling an ant task? 如何通过调用ant任务获取.bat文件中的退出代码?
You can try something like this: 您可以尝试如下操作:
1) In your ant task.xml: make it failing if the resultproperty is not 0. To do it, you can use the fail task with 1)在您的ant task.xml文件中:如果resultproperty不为0,则使其失败。为此,可以将fail任务与
Here is sample code: 这是示例代码:
<exec executable="cmd" resultproperty="javaReturnCode" ...>
...
</exec>
<fail message="java program execution failure" status="${javaReturnCode}">
<condition>
<not>
<equals arg1="${javaReturnCode}" arg2="0"/>
</not>
</condition>
</fail>
2) In your batch file: the %errorlevel% contains the return code of the last command so something like this can work: 2)在您的批处理文件中:%errorlevel%包含最后一个命令的返回码,因此可以执行以下操作:
call ant -buildfile task.xml target1
IF NOT ERRORLEVEL 0 GOTO javaProgramErrorHandlingTarget1
call ant -buildfile task.xml target2
IF NOT ERRORLEVEL 0 GOTO javaProgramErrorHandlingTarget2
REM both ant targets exit normally so continue normal job
...
:javaProgramErrorHandlingTarget1
...
:javaProgramErrorHandlingTarget2
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.