title: Get permanently the output from a shell command running in C++
body: <p>I want to get the output from a shell command (my_program). Here is a example taken from <a href="http://www.minoraddition.com/2011/03/23/popen-execute-shell-command-from-cc/" rel="nofollow">this</a> site:</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("my_program", "r"))){
        return 1;
     }
  
     while(fgets(buff, sizeof(buff), in)!=NULL){
        cout &lt;&lt; buff;
     }
     pclose(in);
  
     return 0;
  }
  </code></pre>
  
  <p><strong>The problem:</strong></p>
  
  <p>I want to run my program permanently and get the output while the program is still running, NOT only get the output from the program once.</p>
  
  <p>Any idea? </p>
  
  <p>Thanks in advanced. </p>