Peter Boughton
Peter Boughton

Reputation: 112190

How do I capture the output of an antcall inside of ant?

I have an Ant script which I run in Eclipse and it outputs in the console like so:

buildStuff:
     [echo] Building <project>
doStuff:
syncStuff:
     [sync] Copying 1 file to <directory>
doOtherStuff:
callWebservice:
     [http] HTTP Request
     [http] ********************
     [http] URL:        <url>
     [http] Method:     GET
     [http] HTTP Response
     [http] ********************
     [http] Status:     200
     [echo] [callWebservice] Success


I would like to put some/all of this output into a property inside the ant script.

With the exec task I can specify an "outputproperty" attribute, but this does not work for antcall task.

So, how do I either access or redirect the console output from within ant?

Upvotes: 2

Views: 1759

Answers (1)

Peter Boughton
Peter Boughton

Reputation: 112190

Ok, found something that works...

The record task can listen to the output and send it to a file.

Apparently it doesn't allow relative paths - the file is created in the same directory as the build script (irrespective of basedir value).

The loadfile task can then be used to put this into a property, followed by delete to clean up afterwards.

It would be nicer to have the recorder output direct to a property, but this doesn't appear to be an option, for whatever reason.

In summary, this worked:

<record name="${CurProject}.status" />

<echo>Building ${CurProject}</echo>
etc...

<record name="${CurProject}.status" action="stop" />
<loadfile srcFile="build/${CurProject}.status" property="Status" />
<delete file="build/${CurProject}.status" />

Upvotes: 4

Related Questions