You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Robert Paris <rp...@hotmail.com> on 2004/01/30 01:03:37 UTC

How grab output to "System.out"?

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?

Thanks!

_________________________________________________________________
Check out the new MSN 9 Dial-up — fast & reliable Internet access with prime 
features! http://join.msn.com/?pgmarket=en-us&page=dialup/home&ST=1


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: How grab output to "System.out"?

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
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 
example).

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 Main.java and decide which 
features you want to use and which you don't.

Cheers
Conor


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: How grab output to "System.out"?

Posted by Jim Fuller <ji...@ruminate.co.uk>.
> From: Robert Paris [mailto:rpjava@hotmail.com] 
> Sent: 30 January 2004 00:04
> To: user@ant.apache.org
> Subject: How grab output to "System.out"?

> 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

Which is normal behavior,

If your question is not ant based, that is 'how do I redirect
System.out' the following link does a clear job of describing the
technique.

http://www.churchillobjects.com/c/12020.html

Cheers, Jim Fuller


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org