[英]Detect timeout in Ant exec task
當您在Ant exec任務中設置timeout屬性並且該任務使進程超時時,是否可以檢測到超時? 我的結果,輸出或錯誤屬性沒有什么可指示超時的有用信息。
當<exec>
由於超時而終止子進程時,父Ant進程將記錄消息Timeout: killed the sub-process
。 但是,由於<exec>
重定向器僅捕獲子outputProperty
輸出,因此<exec>
outputProperty
或errorProperty
沒有超時指示。
要設置一個指示子進程超時的屬性,可以使用<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.