Skip to content

Instantly share code, notes, and snippets.

@andrewn
Created November 12, 2014 20:42
Show Gist options
  • Save andrewn/e6adddf523595116f7b4 to your computer and use it in GitHub Desktop.
Save andrewn/e6adddf523595116f7b4 to your computer and use it in GitHub Desktop.
Node version of popen?
var spawn = require('child_process').spawn;
var sh = spawn('sh');
sh.stdout.on('data', function (data) {
console.log('sh: \n', data.toString());
});
sh.stderr.on('data', function (data) {
console.error('error: \n', data.toString());
});
console.log('ls');
sh.stdin.write('ls\n');
console.log('kill subprocess\n');
sh.kill();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment