title: NodeJS: Can't read binary data from tcpdump using child_process.spawn
body: <p>I can't read binary data from <code>tcpdump -w -</code> in NodeJS.</p>
  
  <pre><code>const {spawn} = require('child_process');
  spawn('tcpdump', ['-w -']).stdout.on('data', (data) =&gt; console.log(data.toString()))
  </code></pre>
  
  <p>It works with text data (without <code>-w -</code>).</p>
  
  <p>I've tried with -U and verified that the libpcap I have on my machine export <code>pcap_dump_flush</code>. I can see with <code>strace</code> that <code>tcpdump</code> is indeed outputting the data. If I spawn another <code>tcpdump</code> with -r - and attach the stdout of the first one to it the data is passed to the second <code>tcpdump</code>. But the stdout data listener is never called and calling <code>stdout.read</code> returns null.</p>
  
  <p>Note:
  I'm aware of pcap, pcap2 and pcap-master but they don't seem to be maintained anymore and didn't compile with the latest version of node and I'd rather use tcpdump anyway.</p>