gpt4 book ai didi

java - 为什么 Ant Exec 任务返回代码与 ERRORLEVEL 值不匹配?

转载 作者:搜寻专家 更新时间:2023-11-01 03:08:18 25 4
gpt4 key购买 nike

我有一个从 Ant exec 任务调用的批处理脚本来编译一些 CSharp 代码。批处理脚本的结构如下

msbuild.exe %ARGS%
echo %ERRORLEVEL%

现在当任务在 Ant 中运行时,我得到以下结果:

 [exec] Time Elapsed 00:00:09.48
[exec] 0

BUILD FAILED
C:\proj\build.xml:410: exec returned: 2

怎么可能 %ERRORLEVEL% 是 0,而 Ant exec 得到的返回码是 2?如果命令不返回代码,是否设置了一些默认错误代码? Ant 文档显示:

error code 2 means 'no such program',

但显然我的批处理文件正在正确执行。

用 Ant 代码更新

<target name="build.csharp" if="isWindowsPlatform">
<exec executable="cmd.exe" failOnError="true">
<arg value="/c"/>
<arg value="build.csharp.bat" />
</exec>
</target>

最佳答案

ANT manual状态:

Errors and return codes

By default the return code of a <exec> is ignored; when you set failonerror="true" then any return code signaling failure (OS specific) causes the build to fail. Alternatively, you can set resultproperty to the name of a property and have it assigned to the result code (barring immutability, of course).

If the attempt to start the program fails with an OS dependent error code, then <exec> halts the build unless failifexecutionfails is set to false. You can use that to run a program if it exists, but otherwise do nothing.

What do those error codes mean? Well, they are OS dependent. On Windows boxes you have to look at the documentation; error code 2 means 'no such program', which usually means it is not on the path. Any time you see such an error from any Ant task, it is usually not an Ant bug, but some configuration problem on your machine.

要获取程序的返回码,您需要使用 exec taskresultproperty 属性.

关于java - 为什么 Ant Exec 任务返回代码与 ERRORLEVEL 值不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14971444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com