Reputation: 11248
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? I don't see anything useful in my result, output, or error properties that would indicate a timeout.
Upvotes: 5
Views: 2517
Reputation: 24134
When <exec>
kills a subprocess due to a timeout, the parent Ant process logs the message 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
.
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.
<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
Upvotes: 3