0

I am running some function form a jar(located under WEB-INF/lib) and I want to read the output(to the console) from my servlet. here is the code:

MsgTranToXML = new MsgTranToXML(); //this is a function inside the jar that prints output

Is this possible? thank's.

Itsik Mauyhas
  • 3,824
  • 14
  • 69
  • 114

1 Answers1

1

I assume your function prints its output via System.out.println.

System.out.println means "call the println() method on the static field out of the class System. This out field is of type PrintStream, and can be reassigned by calling System.setOut() and passing it a new PrintStream of your choice, which you can then use to read the output generated by your function (you may want to take a look at the PipedOutputStream/PipedInputStream classes to achieve that).

Be aware though, that you will also trap the output of every other method that uses System.out.println (including any library you may also use in your application) !

Olivier Croisier
  • 6,139
  • 25
  • 34