title: Send two inputs to stdin from child_process.spawn()
body: <p>Given I have a <code>name.js</code> script which has two prompts as follows:</p>
  
  <pre><code>What is your first name? Foo 
  What is your surname? Bar
  Hello Foo Bar.
  </code></pre>
  
  <p>How would I be able to use <code>child_process.spawn()</code> to send <strong>two inputs</strong> such that the script correctly prints the first and surname?</p>
  
  <p>I have tried using <code>[process].write(Foo); [process].end();</code>, however this results in the stream being closed, unable to accept the surname.</p>
  
  <hr>
  
  <p>The following is the code for <code>name.js</code>. It uses the <a href="https://www.npmjs.com/package/prompts" rel="nofollow noreferrer">prompts</a> npm package.</p>
  
  <pre><code>const prompts = require('prompts');
  
  prompts({
    type: 'text',
    name: 'firstName',
    message: 'What is your first name?',
  })
    .then(response =&gt; {
      prompts({
        type: 'text',
        name: 'surname',
        message: 'What is your surname?',
      })
      .then(secondResponse =&gt; {
        console.log(`Hello ${response.firstName} ${secondResponse.surname}.`);
      });
    });
  </code></pre>
  
  <hr>
  
  <p>The following is a few things I have tried to get this to work, but to no avail.</p>
  
  <pre><code>const {spawn} = require('child_process');
  
  const sampleOne = spawn('name.js');
  sampleOne.stdin.write('Foo\nBar');
  sampleOne.stdin.end(); // This method results in 'First name' being 'FooBar'.
  
  const sampleTwo = spawn('name.js');
  sampleTwo.stdin.write('Foo');
  sampleTwo.stdin.end();
  sampleTwo.stdin.write('Bar');
  sampleTwo.stdin.end(); // Correctly writes 'Foo' as 'First name' but cannot write 'surname' as stdin steam is closed.
  </code></pre>