title: Win32: How to get child process output buffer?
body: <p>I am testing on console standard I/O redirection using CreateProcess(x) function, and redirect the child process output to an anonymous pipe. Somehow, when I read from pipe output, I found that only characters are being redirect to the pipe, not the CHARINFO structure written to output handle using WriteConsoleOutput(x) function.</p>
  
  <p>I would like to know if there is any way to redirect the CHARINFO structure so I can display it to my target output correctly.</p>
  
  <p>These are the steps of what I've done so far:</p>
  
  <ol>
  <li>On console application start, create new console buffer and set it as active console buffer.</li>
  <li>Change new console buffer size and console window size to maximum allow.</li>
  <li>Create anonymous pipe and some more steps to initialize the pipe, base on the <a href="http://support.microsoft.com/kb/190351" rel="nofollow">example</a> shows in MSDN, also referencing <a href="http://www.codeproject.com/Articles/5531/Redirecting-an-arbitrary-Console-s-Input-Output" rel="nofollow">this</a> article.</li>
  <li>Spawn a child process using STARTINFO structure and redirect the I/O/E to the newly created pipe.</li>
  <li>Start new thread to listen child process output.</li>
  <li>Write the output onto active screen buffer, limiting to a small region, say, lower half of the screen buffer.</li>
  </ol>
  
  <p>Step 6 is where I found the problem. At first I though I would get CHARINFO structure, so I try to cast the lpBuffer return by ReadFile(x) function to array of CHARINFO struc. Immediately I see the error. When I examine lpBuffer, I found that only characters stored in lpBuffer, not the Attributes.</p>
  
  <p>Is there a way to redirect the CHARINFO in this case? If yes, how could I identified ReadFile(x) return buffer is array of CHARINFO or array of character? Need to differentiate because I cannot control how the child process output to console.</p>