Skip to content

Instantly share code, notes, and snippets.

@ruddha2001
Created July 7, 2020 21:12
Show Gist options
  • Save ruddha2001/19a5858858a147fc9c6a79eb2727694b to your computer and use it in GitHub Desktop.
Save ruddha2001/19a5858858a147fc9c6a79eb2727694b to your computer and use it in GitHub Desktop.
const spawn = require("child_process").spawn;
function sumOfNumbers(numbers) {
let args = [];
args.push("SumOfNumbers"); // Making our Java filename as the first argument to be picked by the java command
// Push the numbers as the other arguments
numbers.forEach((element) => {
args.push(element);
});
// Starting our worker
console.log("Starting our worker to execute our Java Snippet");
let worker = spawn("java", args);
worker.stdout.on("data", function (data) {
console.log("The sum as processed by our Java Snippet is : " + data);
});
worker.on("close", function (code, signal) {
console.log("Our Java Snippet has finished with an exit code of " + code);
});
}
sumOfNumbers([1, 2, 3]); // Driver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment