Step 1 :
var child = require('child_process').exec;
var path = require('path');
var applicationPath, endIndex = process.resourcesPath.indexOf('/Contents');
applicationPath = process.resourcesPath.substring(0, endIndex); // Entire app path. param 1
var appToKill = 'Electron'; // assuming appName for testing purpose, param 2
console.log('Application Path to START : ' + applicationPath);
//we are passing process id for future reference
var daemon = child('sh restart.sh ' + applicationPath + ' ' + appToKill, function(err, stdout, stderr) {
if (err) {
console.log(err);
}
console.debug("STDOUT :", stdout);
console.warn("STDERR : ", stderr);
});Step 2 , restart.sh :
appToOpen=$1; # app to open, simulating restart ( entire path of app )
killall -9 $2; #app Name, will come here ex : "Electron"
open -nF $appToOpen;Windows: Yes, you can take the params dynmically, just for example i have hardcoded.
taskkill /f /fi "imagename eq Electron.exe"
start "TEST" /high "Electron.exe"App will restart, In case of windows, similar code but some tools quiet.exe will help to start .bat process in hidden mode.
require('child_process').spawn, and using "detached:true" in options will make the process, independent from parent process which started it. It act's as like a daemon thread