title: Redirect command prompt output to GUI and KEEP COLOR?
body: <p>Basically I'm making a command prompt GUI.  User sees command prompt output in a rich text box, and inputs commands in a plain textbox underneath.  I have succeeded in making this work, EXCEPT that to me it seems impossible to get the color information.  For example, if I run a program which outputs red error text, I don't get the color code bytes, they simply aren't in the stream!</p>
  
  <p>Here's what I'm doing now.  To start the process:</p>
  
  <pre><code>ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\Windows\System32\cmd.exe");
  startInfo.UseShellExecute = false;
  startInfo.CreateNoWindow = true;
  startInfo.RedirectStandardOutput = true;
  startInfo.RedirectStandardInput = true;
  startInfo.RedirectStandardError = true;
  
  this.promptProcess = Process.Start(startInfo);
  </code></pre>
  
  <p>Then I create a thread which reads from the output stream and sends that to my text box:</p>
  
  <pre><code>while (true)
  {
      while (this.stream.EndOfStream) ;
  
      //read until there's nothing left in the stream, writing to the (locked) output box                    
      byte [] buffer = new byte[1000];
      int numberRead;
      StringBuilder builder = new StringBuilder();
      do
      {
          numberRead = this.stream.BaseStream.Read(buffer, 0, buffer.Length);
          char[] characters = UTF8Decoder.GetChars(buffer, 0, numberRead);
          builder.Append(characters);
      }
      while (numberRead == buffer.Length);
  
      this.writeToOutput(builder.ToString());
  }
  </code></pre>
  
  <p>Even if I use my fancy command prompt to start an application which would output colored text, I don't get any additional color information (not even the ANSI color codes mixed in with the text).  As you can see above, I'm going to the BaseStream and reading the bytes, then decoding them into UTF8.  Unfortunately, it seems that even the raw bytes do not include the original color information.</p>
  
  <p><strong>How can I get the original stream from the applications I run, without any filtering at all?  I want the raw bytes so that I can do my own color parsing and present correctly-colored console output.</strong></p>
  
  <p>To clarify, I am not asking how to interpret the color codes.  I just want to make them available in the stream.</p>