1

I have written code to execute bat file using nodejs, but it is restricting me to place the bat file at the same location where package.json file is present and it is not accepting absolute path. I am using the following code:

const { spawn } = require('child_process');
  const bat = spawn('cmd.exe', ['/c','coma.bat']);

    bat.stdout.on('data', (data) => {
      console.log('data is : '+data.toString());
    });

    bat.stderr.on('data', (data) => {
      console.error('error is : '+data.toString());
    });

    bat.on('exit', (code) => {
      console.log(`Child exited with code ${code}`);
 });

1 Answer 1

2

it accepts full path (if this is the question):

const { spawn } = require('child_process');
const bat = spawn('cmd.exe', ['/c','C:\\scripts\\somescript.bat']);
Sign up to request clarification or add additional context in comments.

2 Comments

@RohanBatra - I've tried it too and it is working. What is the error you're receiving?
@RohanBatra does the path contains spaces or other special symbols?

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.