title: xp_cmdshell hangs after called exe has exited
body: <p>I have a problem with a hang using xp_cmdshell.</p>
  
  <ol>
  <li><p>The executable is called, performs its work, and exits.  It is not hanging because of a ui prompt in the exe.  The exe is not hanging at all.  The exe disappears from the process list in task manager, and internal logging from the exe confirms that it executed the very last line in the main function</p></li>
  <li><p>the call to xp_cmdshell does NOT return control in SQL.  It hangs on that line (it is the last line of the batch).  Killing the process is ineffective.  It actually requires a restart of sql server to get rid of the hung process (ugh)</p></li>
  <li><p>The hang only happens the first time it is run.  Subsequent calls to the procedure with identical parameters work and exit correctly so long as the first one is hung.  Once SQL is restarted, the first subsequent call will hang again.</p></li>
  <li><p>If it makes any difference, I am trying to receive the return value from the exe -- my sql procedure ends with:</p>
  
  <p>exec @i = xp_cmdshell @cmd; 
  return @i;</p></li>
  <li><p>Activity Monitor is reporting the process to be stuck on a wait type of PREEMPTIVE_OS_PROCESSOPS (what the other developer saw) or PREEMPTIVE_OS_PIPEOPS (what I'm seeing on my current testing)</p></li>
  </ol>
  
  <p>Any ideas?</p>