Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to capture Ant output to a string variable

 
sreenivas jeenor
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,


I am working on ANT.my requirement is to display Ant output on HTML/Jsp page.

normally i am using Ant project to execute the build file.

here is the code-my program runs and shows ant build results/errors in the console,but i want them to be stored on a string and then use that in jsp page.



help me

Thanks
Srinivas
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try replacing the System.out and System.err in lines 5 and 6 with a StringWriter?
 
sreenivas jeenor
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lines 5 and 6 accept only PrintStream object.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declare a ByteArrayOutputStream and wrap it in a PrintStream. Once done, use toByteArray() to get the output and create a String from that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic