你可以尝试这样的事情:
1)在你的蚂蚁task.xml:让它失败如果resultproperty不为0。要做到这一点,你可以使用fail task与
- 该resultProperty不是条件0
- 状态码等于从Java程序
这里返回代码状态为示例代码:
<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)在您的批处理文件:在%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
...
这正是我需要的,非常感谢!我正在尝试这种方式进行测试。 – Una