title: C++ No output from popen
body: <p><strong>tl;dr - Cannot capture output from commands that use RPC to a remote server using any programming language I try, even though these commands output back to the command prompt when typed manually</strong></p>
  
  <p>I've got a function that uses fpipe to issue the netsh command to display stats from our DHCP server.  I do this same fpipe buffer-reading technique elsewhere in my program and it works fine, but here I'm getting no output at all:</p>
  
  <p><strong>EDIT:</strong> I'm simplifying my code to a more proof-of-concept type snippet.  It's actually an all-encompassed .cpp source file that still replicates the issue.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;stdio.h&gt;  // for _popen() and _pclose()
  using namespace std;
  
      int main()
      {
          char buff[512];
          buff[0]=0;
          string cmd="netsh dhcp server 192.168.200.15 scope 192.168.200.0 show clients 1";
          FILE *fpipe = _popen(cmd.c_str(),"r");
          if(fpipe==NULL) cout&lt;&lt;"Failed to open"&lt;&lt;endl; else cout&lt;&lt;"Opened pipe successfully";
          while(fgets(buff,sizeof(buff),fpipe)!=NULL) cout&lt;&lt;buff&lt;&lt;endl;
          _pclose(fpipe);
      }
  </code></pre>
  
  <p>The only output I'm getting is:</p>
  
  <pre><code>Opened pipe successfully
  </code></pre>
  
  <p>But if I copy/paste that command into another command prompt window, it runs fine and spits out many lines immediately.</p>
  
  <p>So where does it go?  Why does nothing ever go into my buffer?</p>
  
  <p>Also, changing the "cmd" string from the netsh to the "dir" command will successfully output dir's output.</p>
  
  <p><strong>EDIT</strong>: Even <code>system(cmd.c_str());</code> gives me no output!</p>
  
  <p><strong>EDIT</strong>: Curiously, <code>cmd="netsh dump";</code> actually outputs fine, but still <code>cmd="netsh dhcp server...</code> does not.  Something weird with the way CMD routes netsh text or... something?  Outside of my comfort zone here.</p>
  
  <p><strong>EDIT</strong>: This is obviously an issue outside of C++ because when I'm in a Python 2.7 shell (this is Windows 7 64-bit, by the way), I try this:</p>
  
  <pre><code>&gt;&gt;&gt; import subprocess
  &gt;&gt;&gt; subprocess.call('dir', shell=True)
   Volume in drive C has no label.
   Volume Serial Number is 2E2B-B34F
  
   Directory of C:\MyDir
  
  09/30/2013 01:24 PM  &lt;DIR&gt;       .
  09/30/2013 01:24 PM  &lt;DIR&gt;       ..
  09/20/2013 10:11 AM          45  test.txt
               1 File(s)       45 bytes
               2 Dir(s)   162,260,246,528 bytes free
  0
  &gt;&gt;&gt; subprocess.call('netsh dhcp server 192.168.200.15 scope 192.168.200.0 show clients 1', shell=True)
  0
  &gt;&gt;&gt;
  </code></pre>