Node.js and command line (cmd.exe)

I am looking for a solution or NPM to invoke a Windows command prompt from node.js.

I want to call several batch files and run them on a machine using node.js, of course with parameters, and also read their output.

+4
source share
1 answer

For this you can use the standard module child_process.spawn () .

From the sample documentation:

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 batfile.bat batch file.

+8
source

Source: https://habr.com/ru/post/1441568/


All Articles