Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2003

Tip: Looking for answers? Try searching our database.

Assign System.err to bit bucket

Thread view: 
RonS - 29 Nov 2003 23:56 GMT
Is there a way to assign System.err so that messages are discarded? I
tried assigning it to null, which compiles, but causes a run time error.
Anthony Borla - 30 Nov 2003 00:13 GMT
> Is there a way to assign System.err so that messages
> are discarded? I  tried assigning it to null, which compiles,
> but causes a run time error.

Try:

   // *NIX / Linux
   PrintStream nps = new PrintStream(new FileOutputStream("/dev/null"));
   System.setErr(nps);

or:

   // Win32
   PrintStream nps = new PrintStream(new FileOutputStream("NUL:"));
   System.setErr(nps);

I hope this helps.

Anthony Borla

P.S.

Remember to save, then reset, the standard error stream. Example:

   // Save old stream
   PrintStream ops = System.err;
   ...
   // Change stream and do stuff with it ...
   nps = ...;
   System.setErr(nps);
   ...
   ...
   // Close stream
   nps.close();

   // Restore old stream
   System.setErr(ops);
Dave Glasser - 30 Nov 2003 04:29 GMT
"Anthony Borla" <ajborla@bigpond.com> wrote on Sun, 30 Nov 2003
00:13:51 GMT in comp.lang.java.help:

>> Is there a way to assign System.err so that messages
>> are discarded? I  tried assigning it to null, which compiles,
[quoted text clipped - 11 lines]
>    PrintStream nps = new PrintStream(new FileOutputStream("NUL:"));
>    System.setErr(nps);

Or this should work on any platform:

   System.setErr(new PrintStream(new OutputStream() {
           public void write(int b) {}
       }));

Signature

Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.

http://qform.sourceforge.net

Anthony Borla - 30 Nov 2003 05:21 GMT
> "Anthony Borla" <ajborla@bigpond.com> wrote on Sun, 30 Nov 2003
> 00:13:51 GMT in comp.lang.java.help:
[quoted text clipped - 22 lines]
>             public void write(int b) {}
>         }));

Yes, indeed, it does, it effectively discards everything sent to it, fully
meeting the OP's requirements, and is quite portable to boot. I think I was
stuck in 'bit bucket' mode :) !

Cheers,

Anthony Borla
RonS - 30 Nov 2003 06:38 GMT
>>Is there a way to assign System.err so that messages
>>are discarded? I  tried assigning it to null, which compiles,
[quoted text clipped - 33 lines]
>     // Restore old stream
>     System.setErr(ops);

Thanks Anthony

Exactly what I needed!

Ron


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.