title: C++ read popen error output into string
body: <p>I'm opening a process via the posix <code>popen()</code> function. E.g. git push, mkdir x, etc.</p>
  
  <p>I can read the output from these commands easily by storing it into a buffer like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  
  using namespace std;
  
  int main() {
  
  FILE *in;
  char buff[512];
  
  if(!(in = popen("mkdir x", "r"))){
      return 1;
  }
  
  // fgets stores the output into buff
  while(fgets(buff, sizeof(buff), in)!=NULL){
      cout &lt;&lt; buff;
  }
  pclose(in);
  
  return 0;
  
  }
  </code></pre>
  
  <p>But then if there is an error with the process, e.g. mkdir fails, then I want to read the error into a string or character buffer.</p>
  
  <p>However, with the code above, if it fails, the error isn't stored in the buffer. I think it is because the error is redirected to standard error instead of standard input.</p>
  
  <p>How do I modify the code above to get the error message returned by bash/the process?</p>