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.

4
  • Does a servlet always have a console? Commented Jun 8, 2016 at 7:43
  • I didn't understant the quastion.... Commented Jun 8, 2016 at 8:00
  • Servlets are only 'alive' for the duration of a request processing. Does the servlet launch the jar, or is the external process already running? Commented Jun 8, 2016 at 8:00
  • It is the servlet that runs this jar, so while the request ends the servlet could not read from 'println'? Commented Jun 8, 2016 at 8:02

1 Answer 1

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) !

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.