Consider the code snippet below.
var exec = require('child_process').exec;
var extraInfo = {'test':1,'passing':'test'};
runWithData(extraInfo);
function runWithData(passedData)
{
exec('/Users/test/Desktop/testcommand', function callback(error,stdout,stderr)
{
if (error)
{
console.log("ERROR",stderr);
}
else
{
console.log(stdout);
}
});
}
Is directly accessing passedData within the callback of exec the correct method? Will it be overwritten if multiple functions are being processed simultaneously? Alternatively, is there a way to bind the information into the callback function so it remains tied to it?