Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a .bat file from node.js passing some parameters?

Tags:

People also ask

Can we pass parameters to batch file?

You simply substitute the parameter for 1 (e.g., %~f2 for the second parameter's fully qualified path name). The %0 parameter in a batch file holds information about the file when it runs and indicates which command extensions you can use with the file (e.g., %~dp0 gives the batch file's drive and path).

How do you run a batch file in Javascript?

The simplest way is like this (this is somewhat close to what you tried already): var wshShell = new ActiveXObject("WScript. Shell"); wshShell. Run("D:\\dir\\user.


I use node.js v4.4.4 and I need to run a .bat file from node.js.

From the location of the js file for my node app the .bat is runnable using command line with the following path (Window platform):

'../src/util/buildscripts/build.bat --profile ../profiles/app.profile.js' 

But when using node I cannot run it, no specific error are thrown.

What am I doing wrong here?


    var ls = spawn('cmd.exe', ['../src/util/buildscripts', 'build.bat', '--profile ../profiles/app.profile.js']);      ls.stdout.on('data', function (data) {         console.log('stdout: ' + data);     });      ls.stderr.on('data', function (data) {         console.log('stderr: ' + data);     });      ls.on('exit', function (code) {         console.log('child process exited with code ' + code);     });