Those 2 commands are running in separate shells.
To get the code, you should be able to check err.code
in your callback.
If that doesn’t work, you need to add an exit
event handler
e.g.
dir = exec("ls -la", function(err, stdout, stderr) {
if (err) {
// should have err.code here?
}
console.log(stdout);
});
dir.on('exit', function (code) {
// exit code is code
});