title: how to get linux command output string and output status in c++
body: <p>I want to get a Linux command's output string as well as command output status in a C++ program. I am executing Linux commands in my application.</p>
  
  <p>for example:
  Command: </p>
  
  <blockquote>
    <p>rmdir abcd</p>
  </blockquote>
  
  <p>Command output string:</p>
  
  <blockquote>
    <p>rmdir: failed to remove `abcd': No such file or directory</p>
  </blockquote>
  
  <p>Command Status:</p>
  
  <blockquote>
    <p>1   (Which means command has been failed)</p>
  </blockquote>
  
  <p>I tried using Linux function <code>system()</code> which gives the output status, and function <code>popen()</code> which gives me output string of a command, but neither function gives me both
  the output string and output status of a Linux command.</p>