title: NodeJS execSync with custom stdout stream for collecting output and logging to terminal on the fly
body: <p>When you use execSync then you can specify stdio: </p>
  
  <p><a href="https://nodejs.org/api/child_process.html#child_process_options_stdio" rel="nofollow noreferrer">https://nodejs.org/api/child_process.html#child_process_options_stdio</a></p>
  
  <p>Number five says that you can pass a Stream object: </p>
  
  <blockquote>
    <ol start="5">
    <li> object - Share a readable or writable stream that refers to a
    tty, file, socket, or a pipe with the child process. The stream's
    underlying file descriptor is duplicated in the child process to the
    fd that corresponds to the index in the stdio array. Note that the
    stream must have an underlying descriptor (file streams do not until
    the 'open' event has occurred).</li>
    </ol>
  </blockquote>
  
  <p>However, I am unable to pass an object. I've tried: </p>
  
  <pre><code>const { PassThrough, Writable } = require('stream');
  const pass     = new PassThrough();
  </code></pre>
  
  <p>Which I found here: </p>
  
  <p><a href="https://nodejs.org/api/stream.html#stream_three_states" rel="nofollow noreferrer">https://nodejs.org/api/stream.html#stream_three_states</a></p>
  
  <p>But I couldn't pass that as stdio: [..., stdout, ...] for <strong>execSync</strong> options method call. </p>
  
  <pre><code>require('child_process').execSync(command, options);
  </code></pre>
  
  <p>Anyone? </p>