title: How to pipe unbuffered data from STDOUT to ServerResponse?
body: <p>How can I pipe the unbuffered output from the child process to HTTP.ServerResponse?</p>
  
  <p>The Node.js code below does work for <em>buffered</em> output, but not for <em>unbuffered</em> output. </p>
  
  <pre><code>var http = require('http'),
      spawn = require('child_process').spawn;
  
  http.createServer(function (req, res) {
      req.on('data', function (data) {
          var ping = spawn("ping", ["127.0.0.1"]);
          ping.stdout.pipe(res);
          ping.stderr.pipe(res);
          req.connection.on('end', function() {
              ping.kill();
          });
      });
  });
  </code></pre>
  
  <p>Here is the output from <code>ping 127.0.0.1</code>:</p>
  
  <pre><code>ping 127.0.0.1
  PING 127.0.0.1 (127.0.0.1): 56 data bytes
  Request timeout for icmp_seq 0
  Request timeout for icmp_seq 1
  </code></pre>
  
  <p>Since <code>ping</code> writes request timeouts to STDOUT as <em>unbuffered</em> data, the code above only works if <code>ping</code> is successful.</p>
  
  <p>I'm using Node.js v0.8.19. </p>