title: CreateProcess: redirect child stdout to parent stdout in C++/Windows
body: <p>According to MSDN this redirects child stdout to parent stdout, but it does not, what is wrong?</p>
  
  <pre><code>   PROCESS_INFORMATION pi;
     STARTUPINFOA si;
  
     ZeroMemory( &amp;si, sizeof(si) );
     si.cb = sizeof(si);
     ZeroMemory( &amp;pi, sizeof(pi) );
     si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
     si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
     si.dwFlags |= STARTF_USESTDHANDLES;
  
     BOOL ret = CreateProcessA( 0, cmd_line, 0, 0, TRUE, CREATE_NO_WINDOW, 0, 0, &amp; si, &amp; pi);
  </code></pre>
  
  <p>using DuplicateHandle does not help:</p>
  
  <pre><code>HANDLE out, err;//global variables
  ...
  PROCESS_INFORMATION pi;
  STARTUPINFOA si;
  
  ZeroMemory( &amp;si, sizeof(si) );
  si.cb = sizeof(si);
  ZeroMemory( &amp;pi, sizeof(pi) );  
  BOOL ret = DuplicateHandle( GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE),  GetCurrentProcess(), &amp;out, 0, TRUE, DUPLICATE_SAME_ACCESS);//todo check ret
  ret = DuplicateHandle( GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE),  GetCurrentProcess(), &amp;err, 0, TRUE, DUPLICATE_SAME_ACCESS);//todo check ret
  
  si.hStdOutput = out;
  si.hStdError = err;
  si.dwFlags |= STARTF_USESTDHANDLES;
  
  ret = CreateProcessA( 0, cmd_line, 0, 0, TRUE, CREATE_NO_WINDOW, 0, 0, &amp; si, &amp; pi);
  </code></pre>