Skip to content

Instantly share code, notes, and snippets.

@dignifiedquire
Created January 8, 2014 14:29
Show Gist options
  • Save dignifiedquire/8317598 to your computer and use it in GitHub Desktop.
Save dignifiedquire/8317598 to your computer and use it in GitHub Desktop.
var cp = require('child_process');
var async = require('async');
function discover(opts, callback) {
var listOfItems = [1,2,3,4,5];
async.map(listOfItems, function (item, cb) {
// Gets executed for every item in the list
// when exec is done it calls the cb
cp.exec(cmd(item), cb)
}, function (error, results) {
// results is an array with all stdouts of the commands you ran.
// do stuff to it here.
// And return using the callback that was used in the beginning.
callback(error, results)
})
}
function cmd(item) {
return 'my awesome cmd ' + item;
}
@jas-
Copy link

jas- commented Jan 8, 2014

Thanks, I really appreciate your help. The updated file is here if your interested in the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment