Reputation: 33
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}`);
});
Upvotes: 1
Views: 6391
Reputation: 57252
it accepts full path (if this is the question):
const { spawn } = require('child_process');
const bat = spawn('cmd.exe', ['/c','C:\\scripts\\somescript.bat']);
Upvotes: 2