Created
October 27, 2020 07:37
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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