gpt4 book ai didi

ant - 运行 Ant exec 任务,没有 "Result:"输出

转载 作者:行者123 更新时间:2023-12-02 12:20:47 25 4
gpt4 key购买 nike

当 Ant exec 任务运行以非零退出状态完成的命令时,exec 任务会输出状态,例如:

 [exec] Result: 1

这是在没有上下文的情况下打印的,因此会让用户感到困惑。即使使用 outputproperty="someproperty"failureonerror="false" 调用 exec 任务,也会打印该信息。我对 grep 等命令使用这样的调用,其中非零输出可能是所需的预期结果。

有没有办法抑制“Result:”输出,而不对 Ant 进程的输出进行任何其他更改?

最佳答案

看一下下面的示例,它使用 JavaScript 来禁用和恢复日志记录。

build.xml

<project name="ant-exec-intentional-fail" default="run">
<target name="run">
<echo>Show that exec logs "Result: 1" by default...</echo>
<exec executable="sh" failonerror="false">
<arg value="-c"/>
<arg value="exit 1"/>
</exec>
<echo>Disabling logging...</echo>
<script language="javascript"><![CDATA[
var savedLoggers = project.getBuildListeners();
for( var i = 0; i < savedLoggers.length; i++ ) {
var logger = savedLoggers[i];
project.removeBuildListener( logger );
}
project.addReference( "savedLoggers", savedLoggers );
]]></script>
<exec executable="sh" failonerror="false" resultproperty="middle-sh-result">
<arg value="-c"/>
<arg value="exit 42"/>
</exec>
<!-- Restore logging. -->
<script language="javascript"><![CDATA[
var savedLoggers = project.getReference( "savedLoggers" );
for( var i = 0; i < savedLoggers.length; i++ ) {
var logger = savedLoggers[i];
project.addBuildListener( logger );
}
]]></script>
<echo>Verify logging works again...</echo>
<exec executable="sh" failonerror="false">
<arg value="-c"/>
<arg value="exit 1"/>
</exec>
<echo>By the way, the middle exec returned: ${middle-sh-result}</echo>
</target>
</project>

输出

run:
[echo] Show that exec logs "Result: 1" by default...
[exec] Result: 1
[echo] Disabling logging...
[echo] Verify logging works again...
[exec] Result: 1
[echo] By the way, the middle exec returned: 42

关于ant - 运行 Ant exec 任务,没有 "Result:"输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41052344/

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