title: powershell command string fails in cmd process, where all other commands seem to work
body: <p>I wrote a <em><a href="https://codereview.stackexchange.com/questions/162546/send-command-and-get-response-from-windows-cmd-prompt-silently">routine</a></em> that allows me to make windows system calls from an application, trap the response into a buffer so the content of the buffer can be used in my application.  Every command I've tried, until today, has worked without a flaw, including those with very large response buffers.  The basic steps are as follows:</p>
  
  <blockquote>
  <pre><code>1) start a child cmd prompt process from application
  2) write a command to it's stdin, eg:
  3) "cmd.exe /c dir"  (returns listing of applications host directory)
  4) capture response from stdout
  </code></pre>
  </blockquote>
  
  <p>for most commands, making the call and getting the response is normally as simple as:</p>
  
  <pre><code>int main(void)
  {
      char *buf = {0};
      buf = calloc(100, 1);
      if(!buf)return 0;
      cmd_rsp("dir /s", &amp;buf, 100);//cmd_rsp is fully defined in the links I provided in post.
                                   //Note: all commands are prepended with 
                                   //'cmd.exe /c ' inside the cmd_rsp function.
      printf("%s", buf);
      free(buf);
  
      return 0;
  }
  </code></pre>
  
  <p>But when I send the command <code>powershell start-sleep -m 2000</code>, nothing is ever sent to <code>stdout</code>, causing application to hang.</p>
  
  <p>Execution flow stops at the <code>ReadFile</code> function, trying to catch at least one byte of data out through the <code>stdout</code> pipe.  ( refer to <em><a href="https://codereview.stackexchange.com/questions/162546/send-command-and-get-response-from-windows-cmd-prompt-silently">code here</a></em> )</p>
  
  <p>I have read (and tried the suggestions in) <em><a href="https://stackoverflow.com/q/24940243/645128">this link</a></em> about this topic, but still have not seen results using the <code>&amp;</code> to concatenate the calls.  i.e., the <code>&amp;</code> <em>does work</em> with combination calls such as:</p>
  
  <pre><code>cmd.exe /c cd c:\\devphys\\msvc\\ &amp;&amp; dir
  </code></pre>
  
  <p>Just not when <code>powershell</code> is called.  </p>
  
  <p>I am hoping someone familiar with this scenario can suggest a different calling convention when using such things as <code>powershell</code> in the command line, Or, suggest a way to break out of <code>ReadFile</code> (called from within the function <code>ReadFromPipe</code> ) when it is clear nothing is coming to <code>stdout</code>. </p>
  
  <p>EDIT:  in the code for <em><a href="https://codereview.stackexchange.com/questions/162546/send-command-and-get-response-from-windows-cmd-prompt-silently">cmd_rsp(...)</a></em> , some may have noticed that inside the function <code>ReadFromPipe</code>, I made an attempt at a timeout using:</p>
  
  <pre><code>//Set timeouts for stream
  ct.ReadIntervalTimeout = 0;
  ct.ReadTotalTimeoutMultiplier = 0;
  ct.ReadTotalTimeoutConstant = 10;
  ct.WriteTotalTimeoutConstant = 0;
  ct.WriteTotalTimeoutMultiplier = 0;
  SetCommTimeouts(g_hChildStd_OUT_Rd, &amp;ct);
  </code></pre>
  
  <p>However, as detailed <em><a href="https://stackoverflow.com/a/13768092/645128">here</a></em> and <em><a href="https://stackoverflow.com/a/35303690/645128">here</a></em> (see comment under post). this method, as a timeout, is not compatible with an implementation using <code>ReadFile</code> and pipes.</p>