ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Conor MacNeill <>
Subject Re: How grab output to "System.out"?
Date Fri, 30 Jan 2004 00:40:31 GMT
On Fri, 30 Jan 2004 11:03 am, Robert Paris wrote:
> I am working with Ant programatically and I need to be able to grab the
> output (outputstream) from programs that run in Ant. I know Ant does this
> as when my program does:
>      System.out.println( "test" );
> Ant actually prints:
>      [Java] test
> Does anyone know what class/method I need to use to do this?

There's more to it than you might expect. Ant uses a class, the 
DemuxOutputStream to route output sent to System.out into Ant's logging 
system. DemuxOutputStream is capable of separating the output generated by 
separate threads to make sure the output is logged against the correct task - 
since Ant can have many tasks running at once in different threads.

The output is passed to the Project object which then decides which task owns 
the output. The output is then sent to that task. By default the output is 
logged as a task message but some tasks will process it further to do things 
like capture output or further route the output to another task (<ant> , for 

Note that DebugOutputStream is setup in System.out in Ant's Main class. In 
general, you need to be aware that once you redirect System.out you will get 
all output in the JVM even if it does not come from Ant. So when you are 
running as part of another system, you need to be clear that this is an OK 
thing to do. In a webapp, it may not be a good idea, for example. This is 
also one of the reasons why it is not recommended to use Main to embed Ant 
into another system (There are others).

The best thing to do when embedding is to look at and decide which 
features you want to use and which you don't.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message