[英]return exit code from ant to a batch file
我的.bat文件中有幾個螞蟻任務要執行。
我的.bat文件如下所示:
調用ant -buildfile task.xml target1
調用ant -buildfile task.xml target2
. 對於每個ant任務,它將執行一個Java程序,並且該程序將通過使用返回退出代碼。
我知道可以通過在ant配置中使用resultproperty來接收退出代碼。
如何通過調用ant任務獲取.bat文件中的退出代碼?
您可以嘗試如下操作:
1)在您的ant task.xml文件中:如果resultproperty不為0,則使其失敗。為此,可以將fail任務與
這是示例代碼:
<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
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.