title: nodejs child_process.spawnSync or child_process.spawn wrapped in yieldable generator which returns output
body: <p>since a while i am trying to reach something that doesn't work out for me so far.</p>
  
  <p>With nodejs, i like to run a interactive sh-command and work with the sh-command output after the command has exited. i like to write a yieldable generator-function that wraps the running of the interactive shell command and returns the output of the shell command.</p>
  
  <h2>Approach 1: shelljs</h2>
  
  <ul>
  <li><a href="https://github.com/arturadib/shelljs" rel="noreferrer">shelljs</a></li>
  <li>I had some success with shelljs, but at some point it wont run further.</li>
  <li>Question 1: is it possible to get shelljs to the point where i can inherit stdio and make the shelljs function yieldable?</li>
  </ul>
  
  <h2>Approach 2: child_process.spawnSync</h2>
  
  <ul>
  <li><a href="https://nodejs.org/api/child_process.html" rel="noreferrer">child_process.spawnSync</a></li>
  <li>at last i discovered child_process.spawnSync and was happy that, at least i can run interactive sh-commands without problems with <code>options: { stdio: 'inherit' }</code></li>
  <li>but i haven't found out how to get back the output of child_process.spawnSync.</li>
  <li>Question 2: How to wrap spawnSync into a generator function that returns the child_process's output?</li>
  </ul>
  
  <h2>Approach 3: co-child-process</h2>
  
  <ul>
  <li>i also tried <a href="https://www.npmjs.com/package/co-child-process" rel="noreferrer">co-child-process</a>. </li>
  <li>it seems to run, but not interactive with stdio. there is a <a href="https://github.com/cojs/child-process/pull/1" rel="noreferrer">issue</a> regarding this, i dont really understand. </li>
  <li>Question 3: could someone explain me/ post a example how co-child-process will work with stdio inherit.</li>
  </ul>
  
  <h2>Approach 4: promisify child_process.spawn() with bluebird</h2>
  
  <ul>
  <li>i opened an <a href="https://github.com/petkaantonov/bluebird/issues/754" rel="noreferrer">issue</a> on bluebird if child_process.spawn() is promisifiable</li>
  </ul>
  
  <p>So my question at all. Can someone post me an example of how to run a interactive shell command that can be wrapped in a yieldable generator function that returns the output of the shell command? i am open for new approaches.</p>
  
  <p>I created a npm module which is available on <a href="https://github.com/divramod/dm-shell" rel="noreferrer">github</a> where you can fork it and contribute.</p>
  
  <p>thx in advance.</p>