title: Getting output of a system command from stdout in C
body: <p>I'm writing a C program under Android/Linux that runs a system command. The command outputs some text to stdout, and I'm trying to capture the output into a string or character array.</p>
  
  <p>For example:</p>
  
  <pre><code>system("ls");
  </code></pre>
  
  <p>would list the contents of the current directory to stdout, and I would like to be able to capture that data into a variable programmatically in C.</p>
  
  <p>How do I do this?</p>
  
  <p>Thanks.</p>