I’ve been doing some more batch file work recently.  I keep getting frustrated that batch files don’t have a way to send output to both the console and a file.  I decided to write a little console application to do this for me.

This is largely untested – it’ll be going through the gauntlet tomorrow at work.  What do you think – is this a reasonably valuable little utility?  Was this the best way to do it?

   1: class Program
   2: {
   3:   static void Main(string[] args)
   4:     {
   5:   string mirrorFile = args[0];
   6:         MirrorWriter writer = new MirrorWriter(mirrorFile);
   7:  
   8:   string s;
   9:   while ((s = Console.ReadLine()) != null)
  10:         {
  11:             writer.WriteLine(s);  
  12:         }
  13:     }
  14: }
  15:  
  16: class MirrorWriter : StringWriter
  17: {
  18:   private string _mirrorFile;
  19:  
  20:   public MirrorWriter(string mirrorFile)
  21:     {
  22:   this._mirrorFile = mirrorFile;
  23:     }
  24:  
  25:   public override void WriteLine(string value)
  26:     {
  27:         Console.WriteLine(value);
  28:  
  29:         var file = File.AppendText(this._mirrorFile);
  30:         file.WriteLine(value);
  31:         file.Close();
  32:     }
  33: }


Usage: ECHO This is my string | EchoMirror.exe Output.txt