所以我目前有一个 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。