Execute bash command in Node.js and get exit code

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
});

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)