Node.js as service, exec doesn't work

我只是一个虾纸丫 提交于 2020-02-03 10:54:05

问题


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.

来源:https://stackoverflow.com/questions/33946992/node-js-as-service-exec-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!