title: Select which handles are inherited by child process
body: <p>When creating a child process in C++ using Windows API, one can allow inheritance of handles from parent to child. In a Microsoft example <a href="http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx" rel="noreferrer">"Creating a Child Process with Redirected Input and Output"</a>, redirecting a child process' std in/out to pipes created by the parent, it is necessary to allow inheritance for the redirection pipes to be usable. </p>
  
  <p>I'm working on a small demo class that launches an external executable, reads the output, and then spits it back to the caller (who records the returned output to a file). I'm trying to build in a time-out feature, where it will only block for a certain amount of time before calling <code>TerminateProcess()</code> on the child and continuing on with life.</p>
  
  <p>However, I've found that by allowing handle inheritance, the child process also has a handle (visible with <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" rel="noreferrer">Process Explorer</a>) to the output file. I do not want the child process to obtain this handle, but the parent in this case (this demo class) is not aware of the handle either, so I cannot currently use <code>SetHandleInformation()</code> to unflag the output file specifically to exclude it from inheritance.</p>
  
  <p>I am certain there must be a better way to inherit <em>ONLY</em> the specific handles that I want, without allowing "blanket" inheritance which passes unintended and undesired handles. Unfortunately I have been unable to find a solution, having browsed as many related MSDN articles as I can find, and having Googled myself into a state of discouragement.</p>
  
  <p>At the very least, I need to do <em>something</em> to remove the handles from the child, without necessarily having those handles within the demo class (they're used by the calling class, and this demo class has no explicit knowledge of their existence).</p>
  
  <p>Any solutions for more selective inheritance? I'm especially interested in the solution that allows me to specifically declare what handles to inherit, and all un-specified handles will not be inherited, if such a solution exists.</p>
  
  <p>Thank you kindly.</p>