Skip to content

Instantly share code, notes, and snippets.

@Southern
Created November 30, 2012 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Southern/00c61b6484fe50c1fb90 to your computer and use it in GitHub Desktop.
Save Southern/00c61b6484fe50c1fb90 to your computer and use it in GitHub Desktop.
var _spawn = require('child_process').spawn,
children = [];
function spawn() {
var id = children.push(_spawn.apply(null, arguments)) - 1;
children[id].on('exit', function() {
delete children[id];
});
// If you want to pipe stuff...
children[id].stdout.pipe(process.stdout);
children[id].stderr.pipe(process.stderr);
}
function cleanup() {
children.forEach(function(child) {
child.kill('SIGINT');
});
}
spawn('echo', [ 'Test' ]);
cleanup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment