[英]Detect timeout in Ant exec task
When you set the timeout attribute in the Ant exec task and the task times out the process, is there a way to detect the timeout? 当您在Ant exec任务中设置timeout属性并且该任务使进程超时时,是否可以检测到超时? I don't see anything useful in my result, output, or error properties that would indicate a timeout.
我的结果,输出或错误属性没有什么可指示超时的有用信息。
When <exec>
kills a subprocess due to a timeout, the parent Ant process logs the message Timeout: killed the sub-process
. 当
<exec>
由于超时而终止子进程时,父Ant进程将记录消息Timeout: killed the sub-process
。 However, since the <exec>
redirector only captures output from the subprocess, there is no indication of the timeout in the <exec>
outputProperty
or errorProperty
. 但是,由于
<exec>
重定向器仅捕获子outputProperty
输出,因此<exec>
outputProperty
或errorProperty
没有超时指示。
To set a property indicating the subprocess timed out, Ant's log output can be captured using the <record>
task as demonstrated in the following example. 要设置一个指示子进程超时的属性,可以使用
<record>
任务捕获Ant的日志输出,如以下示例所示。
<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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.