簡體   English   中英

在Ant exec任務中檢測超時

[英]Detect timeout in Ant exec task

當您在Ant exec任務中設置timeout屬性並且該任務使進程超時時,是否可以檢測到超時? 我的結果,輸出或錯誤屬性沒有什么可指示超時的有用信息。

<exec>由於超時而終止子進程時,父Ant進程將記錄消息Timeout: killed the sub-process 但是,由於<exec>重定向器僅捕獲子outputProperty輸出,因此<exec> outputPropertyerrorProperty沒有超時指示。

要設置一個指示子進程超時的屬性,可以使用<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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM