each-exec v1.0.0
each-exec
A Node module to run commands in parallel
var eachExec = require('each-exec');
eachExec(['echo "foo"', 'echo "bar"'], function(err, stdouts, stderrs) {
if (err) {
throw err;
}
stdouts; //=> ['foo\n', 'bar\n']
stderrs; //=> ['', '']
});
Installation
npm install each-exec
API
var eachExec = require('each-exec');
eachExec(commands , options, callback)
commands: Array
of String
(the commands to run)
options: Object
(child_process.exec options)
callback: Function
It runs the commands using child_process.exec in parallel.
After all the commands have finished, it runs the callback function.
When one of the commands fails, it immediately calls the callback function and the rest of the commands won't be run.
callback(error, stdoutArray, stderrArray)
error: Error
if one of the commands fails, otherwise null
stdoutArray: Array
of String
(stdout of the commands)
stderrArray: Array
of String
(stderr of the commands)
It doesn't pass any values to the second argument and third argument, if one of the commands fails.
execSeries([
'echo foo',
'exit 200',
'echo bar'
], function(err, stdouts, stderrs) {
err.code; //=> 200
stdouts; //=> undefined
stderrs; //=> undefined
arguments.length; //=> 1
});
Callback function is optional.
execSeries(['mkdir foo', 'mkdir bar']);
setTimeout(function() {
fs.existsSync('foo'); //=> true
fs.existsSync('bar'); //=> true
}, 1000);
License
Copyright (c) 2014 Shinnosuke Watanabe
Licensed under the MIT License.
9 years ago