I have a simple nodejs server up and running. I am running into trouble when I try to spawn a child process. the jar file I am trying to access, is in the same directory as the node script. It takes in a command line argument that I am trying to pass in and it outputs data to the command line, which I am trying to pipe into the var child.
var child = require('child_process').spawn('java -jar done.jar',['argument to pass in']);
child.stdout.on('data', function(data) {
console.log(data.toString());
});
child.stderr.on("data", function (data) {
console.log(data.toString());
});
This produces the following error message:
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn java -jar done.jar ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1046:32)
at child_process.js:1137:20
at process._tickCallback (node.js:355:11)
Any ideas?
You're executing java. -jar and done.jar are arguments to pass.
var child = require('child_process').spawn(
'java', ['-jar', 'done.jar', 'argument to pass in']
);
You will also need to specify the full path to java, or make sure that java is specified in the OS path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With