javascript - How to call a java program from node.js? -
i have node.js script , java program in same folder (.class , .java , .js). want call java program node.js script. in terminal can call java program this
java -cp java-json.jar:. plutomake "tests/android.png"
i saw thread how call java program nodejs
and trying same thing, here node.js code
var child = spawn('java', ['-cp java-json.jar:. plutomake', 'tests/android.png']);
this seems run without crashing, nothing happens. java program creates image, if through node, doesn't work. know whats wrong?
thanks
the array of arguments pass should have 1 element per argument. you’re incorrectly combining few of them.
var child = spawn('java', ['-cp', 'java-json.jar:.', 'plutomake', 'tests/android.png']);
checking output , exit code prove useful:
child.on('close', function (exitcode) { if (exitcode !== 0) { console.error('something went wrong!'); } }); // if you’re passing through, though, pass {stdio: 'inherit'} // child_process.spawn instead. child.stderr.on('data', function (data) { process.stderr.write(data); });
Comments
Post a Comment