The Artima Developer Community
Sponsored Link

.NET Buzz Forum
NullTextWriter

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jeff Key

Posts: 481
Nickname: jeffreykey
Registered: Nov, 2003

Jeff Key is legally sane, but questionably competent.
NullTextWriter Posted: Nov 29, 2003 11:31 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Jeff Key.
Original Post: NullTextWriter
Feed Title: Jeff Key
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/jkey/Rss.aspx
Feed Description: Topics revolve around .NET and the Windows platform.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Jeff Key
Latest Posts From Jeff Key

Advertisement

I'm trying to do some profiling on a command line app that uses a number of assemblies that spit out a bunch of debug information via Console.WriteLine (this isn't the intent and the calls have since been removed; I just don't have the latest bits yet).  This is no problem on the command line, as I can redirect output to null via “> nul”.  Unfortunately, this doesn't work when started from a profiler.

The simple solution was to add an optional “-null” argument to the application.  When that argument is given, I replace the standard out with a NullTextWriter, then re-add the standard out at program end in case any exceptions were thrown, etc.  Here's the magic:

public class NullTextWriter : TextWriter  {
    
public override System.Text.Encoding Encoding  {
         
get { return ASCIIEncoding.Default; }
     }
}

You can set the output stream by calling Console.SetOut(TextWriter).  Works for me.

Read: NullTextWriter

Topic: .NET User Groups in the UK Previous Topic   Next Topic Topic: Digger for your smartphone

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use