I don't know how to execute an exe
file in node.js
. Here is the code I am using. It is not working and doesn't print anything. Is there any possible way to execute an exe
file using the command line?
var fun = function() { console.log("rrrr"); exec('CALL hai.exe', function(err, data) { console.log(err) console.log(data.toString()); }); } fun();
Type in bat file START <full file name like E:\\Your folder\\Your file.exe> Type in your . js file: const shell = require('shelljs') shell. exec('E:\\Your folder\\Your bat file.
Double-click an EXE file to run it. EXE files are Windows executable files, and are designed to be run as programs. Double-clicking any EXE file will start it.
Compile one JavaScript file into an executable using nexe In our case, it'll create Windows executable file with the name “executable”. Double-tap on it or right-click and select the run command to start the application.
You can Run your JavaScript File from your Terminal only if you have installed NodeJs runtime. If you have Installed it then Simply open the terminal and type “node FileName. js”. If you don't have NodeJs runtime environment then go to NodeJs Runtime Environment Download and Download it.
If the exe
that you want to execute is in some other directory, and your exe
has some dependencies to the folder it resides then, try setting the cwd
parameter in options
var exec = require('child_process').execFile; /** * Function to execute exe * @param {string} fileName The name of the executable file to run. * @param {string[]} params List of string arguments. * @param {string} path Current working directory of the child process. */ function execute(fileName, params, path) { let promise = new Promise((resolve, reject) => { exec(fileName, params, { cwd: path }, (err, data) => { if (err) reject(err); else resolve(data); }); }); return promise; }
Docs
you can try execFile function of child process modules in node.js
Refer: http://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback
You code should look something like:
var exec = require('child_process').execFile; var fun =function(){ console.log("fun() start"); exec('HelloJithin.exe', function(err, data) { console.log(err) console.log(data.toString()); }); } fun();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With