I need to run a couple of childprocesses and wait until they are done, and instead of using a long chain of callbacks I'm using Q promises. However what ever I try, the childproccesses are executed and Q just continues without waiting for the results.
var clones = repositores.map(function (project) {
return Q.Promise(function (fullfill, reject) {
require('child_process').exec('cd ' + clonepath + ' && git clone ' + project.repourl, function (err, stdout, stderr) {
console.log(stdout);
if (err) {
console.log(stderr);
reject(err);
}
else {
fullfill();
}
});
})
});
Q.all(clones).then(function(){
console.log("Clones complete");
}).done();
This will give "Clone complete" and after comes the clone result.
I've tried with child_process.spawn, fork, exec, execFile with the same result both callbacks and event based.
I've also tried wrapping the Promises in a returned function.
stdout
stream closes?return Q.Promise...
rather thanreturn new Q.Promise...