I am writing a plugin for a closed source Max / MSP application. To work with Max / MSP, my code must extend the class provided by the provider (com.cycling74.max.MaxObject). This class overrides System.err , so calls to System.err.println direct messages to the special error log provided by the application.
This behavior is great for deployment, but testing is problematic. I'm currently trying to write a test suite that runs my code outside of a host application. When I do this, it throws a System.err exception to throw an exception because the application error log is not available.
Does anyone know how I can “undo” the redirection of Max / MSP errors so that during testing calls to System.err.println appear in the java console?
EDIT
I tried @MadProgrammer to suggest caching a PrintStream error link before creating my Max object.
import com.cycling74.max.*; public class MyMaxObject extends MaxObject{ public MyMaxObject(){} public static void main(String[] args){ PrintStream oldError = System.err; MyMaxObject o = new MyMaxObject(); System.setErr(oldError); }
I can't get this to work. When I run this code in the debugger, I find that System.err is of type com.cycling74.io.ErrorStream in the first line of my main method. It seems that by then the redirection has already occurred. If so, how can I get a link to the error stream before redirecting it? (Where could I put this code, if not at the top of Main ?)
EDIT 2
Ok, got it. I just needed to move my test code (e.g. Main method above) to a separate class. As soon as I did this, @MadProgrammer's solution worked perfectly.
dB ' source share