title: How can I flush a child process from nodejs
body: <p>I invoke an executable C program from nodejs using spawn, but the C program seems not be flushed every time. Then, my node program can only output the child process' stdout when the buffer is full(4K) or the child process exit.</p>
  
  <p>To simply the scenario, the two parts code should be:</p>
  
  <p><em>invoke.js</em></p>
  
  <pre><code>var spawn = require("child_process").spawn;
  
  var ps = spawn("./echo");
  ps.stdout.on("data", (data) =&gt; {
      console.log(`${data}`); 
  });
  process.on("SIGINT", ps.kill);
  </code></pre>
  
  <p><em>echo.c</em></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;unistd.h&gt;
  
  static volatile int keep = 1;
  
  void intHandler(int d){
      keep = 0;
  }
  
  int main(){
      signal(SIGINT, intHandler);
      int count = 0;
      while(keep) {
              printf("%d hello world!\r\n", ++count);
              sleep(1);
      }
  }
  </code></pre>
  
  <p><strong>How could I get the output from echo in the invoke.js synchronus? One important thing is I cannot modify the echo.c, I only have binary</strong></p>