title: exec 'npm init' programmatically with node child process, but could not know when it finished
body: <p>I use <code>child_process.exec</code> to run <code>npm init</code>, I can let it create package.json, but after creating, my stdin seems still open, I want to know when my child process finished so I maybe close the stdin, but I could not know when it finished.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>var child = exec('npm init', function (err, stdout, stderr) {
  
      console.log('over');
  });
  child.stdout.on('data', function(data) {
  
      process.stdout.write(data);
  
      //process.stdin.resume();
  });
  child.stdout.on('end', function() {
      console.log('end out');
  });
  child.stdout.on('close', function() {
      console.log('close out');
  });
  child.on('exit', function() {
      console.log('exit');
  });
  child.on('close', function() {
      console.log('close');
  });
  child.on('disconnect', function() {
      console.log('disconnect');
  });
  
  // read stdin and send to child process
  process.stdin.on('readable', function() {
  
      var chunk = process.stdin.read();
  
      if(chunk !== null) {
          child.stdin.write(chunk);
      }
  });
  </code></pre>
  
  <p>None of events fired after it finishing create package.json, so how to close it when it finished?  </p>