I am trying to run two functions on javascript node.js one after the other These are the two functions
This functions runs a bat file
function loadTime() {
var exec = require('child_process').exec;
exec('C:\\Temp\\tasks\\acis\\runme.bat', function(error, stdout, stderr) {
console.log('stdout: ' + stdout);
if (error !== null) {
console.log('exec error: ' + error);
}
});
}
I have to wait for the result of this bat file to run the next function, which is
function parseTime() {
var parser = new xml2js.Parser();
fs.readFile('C:\\Temp\\tasks\\acis\\2.sat\\2.sat.response.xml', function(err, data) {
parser.parseString(data, function(err, result) {
var timeString = result.Message.Response[0].Events[0].MessageReportEvent[8].$.Message;
var fileTime = timeString.substr(13, 20);
console.log(fileTime);
});
});
}
But in javascript when I run this as
loadTime();
parseTime();
It seems parseTime()
function starts to run before loadTime()
finishes running. How do I run parseTime()
after loadTime()
is finished?