使用 NSSM 在 windows 服务中启动 NodeJs 子进程不起作用

Using NSSM to start a NodeJs Child process within a windows service is not working

所以我目前有一个 Nodejs 应用程序,它生成一个执行 java 应用程序的子进程,当直接从命令提示符 运行 时,它工作得很好。

http.createServer(function (request, response) {

console.log('Started Executing Request! \n' );

const { exec } = require('child_process');
exec('"C:\Program Files\Java\jdk1.8.0_172\bin\java.exe" -jar "C:\Temp\myjava.jar"', (err, stdout, stderr) => {
  if (err) {
      console.log('There was an error! ' + err);
    // node couldn't execute the command
    return;
  }

  // the *entire* stdout and stderr (buffered)
  console.log('stdout: ' + stdout);
  console.log('stderr: ' + stderr);
});

console.log('Finished Executing Request! \n' );
}).listen(8087);

// Console will print the message
console.log('Server running at http://127.0.0.1:8087/ \n');

我遇到的问题是,当将其放入服务时,它似乎不想执行 java 应用程序。我将它输出到一个日志文件,我在日志中确实有 "Started Executing Request" 和 "Finished Executing Request!" 但 java 没有执行。

请务必在服务的“登录”选项卡上设置您的用户帐户:

指定您在 "run directly from the command prompt" 时登录的帐户,以便 Java 可以找到其工作所需的重要环境变量(例如 JAVA_HOME)。

这些环境变量可能在您的 "Local System" 帐户中不可用,这就是为什么您在 运行 java 那里遇到麻烦的原因...

我试图打印到标签打印机,结果证明这是打印机驱动程序本身的问题。似乎从服务打印很容易出现问题,所以我走了一条不同的路。我最后做的是创建一个自托管桌面应用程序,该应用程序最小化到 windows 上的系统托盘。上述应用程序在 mac 和 linux.

内正常运行