3

I'm running Node.js project as service using nssm. When user clicks button on my nodejs website it should run require('child_process').exec('cmd /c batfile.bat', function({ res.send(somedata); }); but instead it just skips running bat file and jumps to res.send(somedata). Why is that? When I run Node.js using cmd and npm start server.js it works fine. How can I make exec work while running nodejs as service?

Edit, some code:

require('child_process').exec('cmd /c batfile.bat', function(){

        var log = fs.readFileSync('logs/batlog.log', 'utf8');
        var html = fs.readFileSync('logs/batlog.htm', 'utf8');
        var json = {"log": log, "html": html};
        res.send(json);   

      });

and the batfile.bat is supposed to generate those 2 files but it just doesn't if I run nodejs as service.

Daniel
  • 338
  • 3
  • 13
  • 1
    Can we see some code? Maybe a problem with how you are controlling the child process. – simon-p-r Nov 26 '15 at 22:33
  • I am having a similar problem with execFile. The executable file would not run when the nodejs script is running as a service using nssm. But if I run the script in command prompt, it works fine. Have you found a solution? – K Hsueh Dec 02 '15 at 08:26

0 Answers0