I need to use the Java method getter of this class:
public class GetAyudas {
public static String[] getter(String correo){
String[] res;
if(correo == "[email protected]"){
return res = new String[]{"Sergio","Durán","Vega"};
}
if(correo == "[email protected]"){
return res = new String[]{"Ramón","Y","Cajal"};
}
else{
return res = new String[]{"Nada","De","Nada"};
}
}
public static void main(String[] args) {
System.out.println(getter(args[args.length-1]).toString());
}
}
in Node JS, so I thought that I could call the main method with the argument and save the returned array in the standard output to use it in Node JS following the next code:
const spawn = require("child_process").spawn;
function getAyudas(email) {
let args = [];
args.push("GetAyudas");
args.push(email);
let worker = spawn("java", args);
worker.stdout.on("data", function (data) {
return data;
});
}
let res = getAyudas("[email protected]");
console.log(res);
console.log(typeof res);
But it doesn't work: res is undefined. How can I call and use getter in a Node JS document ?
console.log(res)instead of thereturn data(so you haveconsole.log(data))? You cannot return out of the outer function from an inner function.==is incorrect. Instead, use theequalsmethod. Also, callingtoStringon an array does not provide useful output. UseArrays.toString(getter(args[args.length-1]))GetAyudas.classavailable in the classpath?