I am working with Nodejs to create a tester module. So I need to use exec. This code work and is doing well:
const { exec } = require('child_process');
var nb_test = 1
var return_array = [nb_test];
var finished = 0;
var i = 0;
while (i < nb_test)
{
var env = { "NB_MALLOC": i.toString()};
console.log("coucou");
console.log(i);
exec("ls", { env }, function (error, stdout, stderr) {
console.log(stdout);
return_array[i] = { stdout, error, stderr };
finished++;
});
i++;
}
but if I had this at the end, nothing is executed, the code never enter in the callback
j = 0
while (j < nb_test){}
Any Idea why ?