Una*_*Una 1 java ant batch-file exit-code
我的.bat文件中有几个ant任务要执行.
我的.bat文件如下:
调用ant -buildfile task.xml target1
调用ant -buildfile task.xml target2
对于每个ant任务,它将执行一个java程序,程序将使用System.exit()返回退出代码.
我知道可以通过在ant配置中使用resultproperty来接收退出代码.
如何通过调用ant任务获取.bat文件中的退出代码?
你可以尝试这样的事情:
1)在你的蚂蚁task.xml:让它失败如果resultproperty不为0.要做到这一点,你可以用失败的任务与
这是示例代码:
<exec executable="cmd" resultproperty="javaReturnCode" ...>
...
</exec>
<fail message="java program execution failure" status="${javaReturnCode}">
<condition>
<not>
<equals arg1="${javaReturnCode}" arg2="0"/>
</not>
</condition>
</fail>
Run Code Online (Sandbox Code Playgroud)
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
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6289 次 |
| 最近记录: |