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
1

1 Answer 1

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);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.