当你在Ant exec任务中设置了timeout属性并且任务超时了进程,有没有办法检测到超时?我在我的结果、输出或错误属性中没有看到任何有用的内容来指示超时。
<exec>
因超时而终止子进程时,父 Ant 进程会记录消息Timeout: killed the sub-process
。但是,由于 <exec>
重定向器只捕获子进程的输出,因此无法在 <exec>
的 outputProperty
或 errorProperty
中指示超时情况。<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