title: Writing into stdout with MFC and read stdout by python Popen
body: <p>I want to write into <code>std::cerr</code> or <code>std::cout</code> with my MFC application. In a python script I call this application and I want to read from <code>stdout</code> or <code>stderr</code>.
  Both is not working. Just using <code>std::cout</code> yields no output. After <code>AllocConsole()</code> I was at least able to print to a debug console. Unfortunately, there is still no output on the python site.</p>
  
  <p>In my MFC application I initialize a console to write to with this code:</p>
  
  <pre><code>void BindStdHandlesToConsole()
  {
    // Redirect the CRT standard input, output, and error handles to the console
    freopen("CONIN$", "r", stdin);
    freopen("CONOUT$", "w", stdout);
    freopen("CONOUT$", "w", stderr);
  
    std::wcout.clear();
    std::cout.clear();
    std::wcerr.clear();
    std::cerr.clear();
    std::wcin.clear();
    std::cin.clear();
  }
  
  // initialization
  BOOL foo::InitInstance()
  {
    // allocate a console
    if (!AllocConsole())
      AfxMessageBox("Failed to create the console!", MB_ICONEXCLAMATION);
    else 
      BindStdHandlesToConsole();
  </code></pre>
  
  <p>On the python site, I try to print the output.</p>
  
  <pre><code>process = subprocess.Popen(args,stdout=subprocess.PIPE,shell=True)    
  output = process.stdout.read()
  process.wait()
  </code></pre>
  
  <p>Is there a way to make my MFC program really write and the python script read the standard output?</p>