Reputation: 45023
I'm looking for solution or NPM for calling Windows command line from node.js application.
What I want is call some batch files and run them on machine with node.js, of course with parameters and also read their output.
Upvotes: 4
Views: 8523
Reputation: 17136
You can use the standard module child_process.spawn() for this.
From the documentation example:
var spawn = require('child_process').spawn,
ls = spawn('ls', ['-lh', '/usr']);
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);
});
Replace 'ls'
with 'c:/windows/system32/cmd.exe'
, and ['-lh', '/usr']
with ['/c', 'batfile.bat']
to run the batch file batfile.bat
.
Upvotes: 7