CMD still running when packaged app executed from CMD


#1

I’m calling my Electron Packaged App from a CMD, when I close my app, the CMD is still up, like listening to the app.
I tried everything, even the “removealllisteners” thing…

This is my code

app.on('quit', function (event, exitCode) {
process.emit('exit', exitCode)
})
process.exit = app.exit

app.on("window-all-closed", function() {
app.quit();
});

app.on('before-quit', () => {
if (process.platform !== "darwin") {
var cerrarSesion = async function() {
try {
SQLINSERT =
"DELETE FROM SESION_USUARIO WHERE USUARIO='" + usuarioSistema + "'";
console.log("SQL INSERT " + SQLINSERT);
const pool = await poolPromise;
const result = await pool.request().query(SQLINSERT, err => {
if (err) {
console.log(err);
}
});
} catch (err) {
console.log(err);
}
};
cerrarSesion();
}
});

image


#2

I am having this same issue. I have added events for window-all-closed and also on app.quit() , and also there are no running process for myapp.exe after closing the app from window. All processes seems closed. But still in command prompt the it seems still running, so I had to explicitly press Ctrl+C to return.

However if I press Ctrl+C on command line itself, myapp.exe windows closes and command exits.

// Quit when all windows are closed.
app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

// Quit when all windows are closed.
app.on('quit', function () {
  console.log('Press Ctrl + C');
  process.exit(0);
})