title: Write to spawned process stdin nodejs?
body: <p>I have a script that I want to run from another one. The problem is that the child script (process) needs an user input before it continues.</p>
  <pre><code>var child = spawn('script');
  child.stdin.setEncoding('utf8');
  child.stdout.on('data', function (data) {
      console.log(data.toString().trim()); // tells me to input my data
      child.stdin.write('my data\n');
  });
  </code></pre>
  <p>After I input my data the child script should continue but instead it hang in there.</p>
  <h1>Solution</h1>
  <p>Actually the above code work for me. I'm using <a href="https://github.com/visionmedia/commander.js" rel="noreferrer">commander.js</a> in the child script to prompt the user for action. Here is how I respond to a child's script prompt:</p>
  <pre><code>child.stdout.on('data', function (data) {
      switch (data.toString().trim()) {
          case 'Username:':
              child.stdin.write('user');
              break;
          case 'Password:':
              child.stdin.write('pass');
              break;
      }
  });
  </code></pre>
  <p>Same thing work with <a href="https://github.com/jprichardson/node-suppose" rel="noreferrer">suppose</a>:</p>
  <pre><code>var suppose = require('suppose');
  
  suppose('script')
      .on('Username: ').respond('user')
      .on('Password: ').respond('pass')
  .error(function (err) {
      console.log(err.message);
  })
  .end(function (code) {
      console.log(code);
      done();
  });
  </code></pre>