gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:23:41 24 4
gpt4 key购买 nike

所以我目前有一个 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应用程序。我将其输出到日志文件,并且确实有“开始执行请求”和“完成执行请求!”在日志中,但 java 未执行。

最佳答案

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

enter image description here

指定“直接从命令提示符运行”时登录的帐户,以便 Java 可以找到完成其工作所需的重要环境变量(例如 JAVA_HOME)。

这些环境变量可能在您的“本地系统”帐户中不可用,这就是您在那里运行 java 时遇到问题的原因......

关于java - 使用 NSSM 在 Windows 服务中启动 NodeJs 子进程不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54139131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com