title: How can I redirect stdout to some visible display in a Windows Application?
body: <p>I have access to a third party library that does "good stuff."  It issues status and progress messages to stdout.  In a Console application I can see these messages just fine.  In a Windows application they just go to the bit bucket.</p>
  
  <p>Is there a fairly simple way to redirect stdout and stderr to a text control or other visible place.  Ideally, this would not require any recompiles of the third party code.  It would just intercept the steams at a low level.  I'd like a solution where I just #include the header, call the initialization function and link the library as in...</p>
  
  <pre><code>#include "redirectStdFiles.h"
  
  void function(args...)
  {
    TextControl* text = new TextControl(args...);
    initializeRedirectLibrary(text, ...);
  
    printf("Message that will show up in the TextControl\n");
    std::cout &lt;&lt; "Another message that also shows up in TextControl\n";
  }
  </code></pre>
  
  <p>Even better would be if it used some interface that I could override so it is not tied to any particular GUI library.</p>
  
  <pre><code>class StdFilesRedirector
  {
    public:
      writeStdout(std::string const&amp; message) = 0;
      writeStderr(std::string const&amp; errorMessage) = 0;
      readStdin(std::string &amp;putReadStringHere) = 0;
  };
  </code></pre>
  
  <p>Am I just dreaming?  Or does anyone know of something that can do something like this?</p>
  
  <p>Edit after two answers:  I think using freopen to redirect the files is a good first step.  For a complete solution there would need to be a new thread created to read the file and display the output.  For debugging, doing a 'tail -f' in a cygwin shell window would be enough.  For a more polished application... Which is what I want to write... there would be some extra work to create the thread, etc.</p>