title: Buffer returned by child_process.execSync is incomplete
body: <p>I have the following script which executes a shell command:</p>
  
  <pre><code>#!/usr/bin/env node
  
  const { execSync } = require('child_process');
  
  try {
      const data = execSync(
          'yarn licenses generate-disclaimer --prod',
          { encoding: 'utf8', maxBuffer: 50 * 1024 * 1024 }
      );
  
      console.log(data.length);
  
      return true;
  } catch (error) {
      console.error(`Failed to generate disclaimer: ${error.message}`);
      return false;
  }
  </code></pre>
  
  <p><code>data</code> is a <code>Buffer</code> containing <code>stdout</code> of the child process. As I understand, the way to convert it to a string is to use the <code>.toString()</code> method, but in my case the string is incomplete. The command I am trying to execute is supposed to produce ~500 KB of data, but <code>buffer.length</code> is 43741 (that's ~43 KB). </p>
  
  <p>The problem is probably that <code>yarn licenses</code> output contains some special characters which result in the buffer being incomplete. If I replace the command with <code>printf "%0.s-" {1..500000}</code>, the buffer is complete.</p>
  
  <p>I am using the latest node version (8.7.0).</p>
  
  <p>Any thoughts/suggestions?</p>
  
  <hr>
  
  <p><em>EDIT:</em> Appending <code>| tr "\0" "\n"</code> to the command increases the buffer size to ~122 KB, so @YaroslavAdmin is definitely looking in the right direction. The result is still incomplete though. How do I make sure all special characters are escaped?</p>