检测Ant exec任务中的超时时间

5

当你在Ant exec任务中设置了timeout属性并且任务超时了进程,有没有办法检测到超时?我在我的结果、输出或错误属性中没有看到任何有用的内容来指示超时。

1个回答

3
<exec> 因超时而终止子进程时,父 Ant 进程会记录消息Timeout: killed the sub-process。但是,由于 <exec> 重定向器只捕获子进程的输出,因此无法在 <exec>outputPropertyerrorProperty 中指示超时情况。
为了设置一个指示子进程超时的属性,Ant 的日志输出可以使用 <record> 任务来捕获,如下例所示。
<target name="exec-timeout">
  <record name="exec.log" action="start" />
    <exec executable="java" timeout="1500">
      <arg line="-jar /path/to/executable.jar" />
    </exec>
  <record name="exec.log" action="stop" />      

  <condition property="timed-out" else="false">
    <resourcecontains resource="exec.log"
        substring="Timeout: killed the sub-process" />
  </condition>
  <delete file="exec.log" />

  <echo message="exec timed out: ${timed-out}" />
</target>

输出

exec-timeout:
     [exec] Timeout: killed the sub-process
     [exec] Result: 143
     [echo] exec timed out: true

BUILD SUCCESSFUL
Total time: 2 seconds

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接