0

Is there a way where I can invoke a windows batch file from inside the javascript code? Or any other healthy way to do the below through any node package?

scripts.bat

 ECHO "JAVASCRIPT is AWESOME"
  PAUSE

scripts.js

// Code to read and run the batch file //

On the command prompt:

C:/> node scripts.js
Compo
  • 36,585
  • 5
  • 27
  • 39
Satyajit Patnaik
  • 114
  • 4
  • 14
  • 1
    Possible duplicate of [How to execute a .bat file from node.js passing some parameters?](https://stackoverflow.com/questions/36601121/how-to-execute-a-bat-file-from-node-js-passing-some-parameters) – Ruud Helderman Mar 13 '18 at 13:20

1 Answers1

1

One way to do this is with child_process. You just have to pass the file you want to execute.

const execFile = require('child_process').execFile;
const child = execFile('scripts.bat', [], (error, stdout, stderr) => {
  if (error) {
    throw error;
  }
  console.log(stdout);
});
harymitchell
  • 155
  • 7