Skip to content

Instantly share code, notes, and snippets.

@tinshade
Created October 27, 2020 07:37
Show Gist options
  • Save tinshade/1a30f1e781542fca05865888bc7eec6a to your computer and use it in GitHub Desktop.
Save tinshade/1a30f1e781542fca05865888bc7eec6a to your computer and use it in GitHub Desktop.
Here's as small script to run an external EXE using NodeJS. I used this to run a dependency EXE from my ElectronJS application.
function runExternal(){
var execFile = require('child_process').execFile, child;
//The `process.cwd()` //Gets the current working directory.
//Just writing the name of the exe file and being in the same directory does not work!
child = execFile(process.cwd()+'nameofexe.exe', function(error,stdout,stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: '+ error.code);
console.log('Signal received: '+ error.signal);
}else{
console.log("Console output from the exe: "+stdout);
console.log("Console error from the exe: "+stderr);
}
});
child.on('exit', function (code) {
console.log('Child process exited '+ 'with exit code '+ code); //Code 0 means all good.
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment