Reputation: 93
So i currently have a Nodejs application that spawns a child process that executes a java application and this is working just fine when ran directly from the command prompt.
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');
The problem i have is when put this into a service it doesn't seem to want to execute the java application. I have it outputing to a log file and i do have the "Started Executing Request" and the "Finished Executing Request!" within the log but the java is not executed.
Upvotes: 0
Views: 890
Reputation: 93
I was trying to print to a label printer so what this turned out to be a problem with the printer driver itself. Seems printing from a service is prone to issues so i went a different route. What i ended doing was i created a self hosted desktop application that minimized to the system tray on windows. The above application worked properly within mac and linux.
Upvotes: 0
Reputation: 2433
Please be sure to set your user account on your service's Log On tab:
Specify the account you are logged in to when you "run directly from the command prompt", so that Java can find important environment variables it needs to do its work (e.g. JAVA_HOME).
Those environment variables are probably not available in your "Local System" account, which is why you have trouble running java there...
Upvotes: 1