0

Can someone help me in finding a solution for executing a batch file using java-script, i am currently working with nw.js and i tried couple of things which worked for .exe but not for .bat

var execFile = require 
('child_process').execFile, child;
child = execFile('C:\\WorkLog\\Software\\abc.exe', //works
//child = execFile('C:\\PDFRotation\\Run.bat', //not working 
2
  • rather looks like node.js Commented Jul 21, 2015 at 20:02
  • @npocmaka nw.js is a JS library to call Node modules from the DOM. Commented Jul 21, 2015 at 20:04

2 Answers 2

2

A batch program is not really an executable, so you might have to use cmd.exe to invoke the batch file try something like:

var spawn = require('child-process').spawn;

spawn('cmd.exe', ['yourfile.bat']);
Sign up to request clarification or add additional context in comments.

1 Comment

i tried something like this but this is not working :- var spawn = require('child_process').spawn,child; child = spawn('cmd.exe', ['C:\\PDFRotation\\Run.bat']); child.stderr.setEncoding('utf8'); child.stderr.on('data', function (data) { if (/^execvp()/.test(data)) { console.log('Failed to start child process.'); } });
1

You don't actually execute a batch file. You execute cmd.exe and give it the batch file as a parameter.

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.