title: Redirecting Pipe Output in C++
body: <p>I’m looking for a C/C++ way to execute a shell command and store the output of that command in a <code>std::string</code> or file, <em>without</em> the output being automatically printed to the console.</p>
  <p>All approaches I’ve seen can do exactly that, but also print the execution result to the console.</p>
  <p>For example with a combination of</p>
  <pre><code>FILE* pipe = popen(&quot;ls&quot;, &quot;r&quot;);
  </code></pre>
  <p>and</p>
  <pre><code>fgets()
  </code></pre>
  <p>I’m able to do just that, but with the printing to the console.</p>
  <p>Is there perhaps a way to redirect the stream’s buffer from std::cout to std::sstream, or has it semething to do with Ubuntu?</p>
  <p>Any help is appreciated :)</p>