Skip to content

Instantly share code, notes, and snippets.

@mklabs
Created September 12, 2011 19:39
Show Gist options
  • Select an option

  • Save mklabs/1212179 to your computer and use it in GitHub Desktop.

Select an option

Save mklabs/1212179 to your computer and use it in GitHub Desktop.
spawn and pipe
var spawn = function spawn(cmd, args, callback) {
var stderr = [], stdout = [],
ch = child.spawn(cmd, args);
ch.stdout.pipe(process.stdout, {end: false});
ch.stderr.pipe(process.stderr);
ch.stdout.on('data', function(data) { stdout[stdout.length] = data; });
ch.stderr.on('data', function(data) { stderr[stderr.length] = data; });
ch.on('exit', (callback || function (code) {
console.log('done', arguments);
}));
return ch;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment