dcsimg
Suppress System.err
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   John_Ewing
Posted On:   Thursday, April 22, 2004 05:59 AM

I want to suppress System.err. I am developing on Websphere 4. I want it to work in Windows and Unix.



Something like this:

			
System.setErr(null);
//Black box code that generates System.err
System.setErr(defalt settings);




Thanks!!


~John

Re: Suppress System.err

Posted By:   Sean_Owen  
Posted On:   Thursday, April 22, 2004 08:45 AM


import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class Test {
public static void main(String[] args) {
System.err.println("Before");
PrintStream sysErr = System.err;
PrintStream dummy = new PrintStream(new ByteArrayOutputStream());
System.setErr(dummy);
System.err.println("During");
System.setErr(sysErr);
System.err.println("After");
}
}


As suggested in the other link, you should implement a dummy PrintStream, ideally, that just throws away all its input. Collecting the output in a byte array, as above, is unnecessary and wastes memory of course.

Re: Suppress System.err

Posted By:   John_Ewing  
Posted On:   Thursday, April 22, 2004 07:46 AM

I found this code, which is what I was looking for:

http://developer.apple.com/qa/java/java11.html
About | Sitemap | Contact