Created
July 7, 2020 21:12
-
-
Save ruddha2001/19a5858858a147fc9c6a79eb2727694b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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