title: Anonymous Pipes
body: <p>I've written a two short programs that use anonymous pipes to communicate.  The parent process shares the pipe handles by setting the standard IO handles for the child:</p>
  
  <pre><code>// -- Set STARTUPINFO for the spawned process -------------------------
  ZeroMemory(&amp;m_ChildSI, sizeof(STARTUPINFO));
  GetStartupInfo(&amp;m_ChildSI);
  
  m_ChildSI.dwFlags       = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
  m_ChildSI.wShowWindow   = SW_HIDE;
  m_ChildSI.hStdError     = m_pipeChild.WritePipeHandle();
  m_ChildSI.hStdOutput    = m_pipeChild.WritePipeHandle();
  m_ChildSI.hStdInput     = m_pipeParent.ReadPipeHandle();
  </code></pre>
  
  <p>The child acquires a read pipe handle with a call to <a href="http://msdn.microsoft.com/en-us/library/ms683231(VS.85).aspx" rel="nofollow noreferrer">GetStdHandle</a>:</p>
  
  <pre><code>hReadPipe = GetStdHandle(STD_INPUT_HANDLE)
  </code></pre>
  
  <p>My question is:
  The pipe handles are created by the parent process that calls <a href="http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx" rel="nofollow noreferrer">CloseHandle</a>() on them, once parent and child have finished communication.</p>
  
  <p>Does the child also have to call CloseHandle() also?  I was thinking that because these are the standard IO handles, that they'd be automatically deallocated when the process folds.</p>
  
  <p>thanks!</p>