Is there a way for me to intercept the STDERR stream that is being used from an external JAR file?
My situation is that I have my own program using STDERR for XYZ, and an external JAR that uses STDERR for ABC. I want to merge both so that they are formatted correctly for the end user, but I cannot figure out how to catch or redirect or (what is the right term?) the JAR’s STDERR?
Thanks,
The standard error stream in java programs is
System.errand standard output stream isSystem.out.You can override these both using the System.setErr(java.io.PrintStream) and System.setOut to a PrintStream object. But this will be replaced globally. Provide an implementation of a PrintStream that will do the formatting and set this as an standard error stream for both.
If you have two different processes, then you can get another processes’s error stream (as an input stream) read content from it (fromat it) and write it to your standard error stream.