I have Foo.java file
package mypack;
class Foo {
public int add (int a, int b) {
return a+b;
}
}
and a Bar.java
package mypack;
class Bar {
public static void main (String args[]) {
Foo instance = new Foo();
System.out.println(Foo.add(2, 3));
}
}
and I have a server.js file in which I am using shelljs to read the outputs and print it in the terminal shell.
var shelljs = require('shelljs');
shelljs.exec('java -cp bin mypack.Bar', function (code, output) {
console.log(output);
});
when I run node server.js
I get the output
5
5
The first one is getting printed by the java print statement while the second one is printed by nodejs console statement. My question is how can I modify the java output such that it will only be read by the node and not printed in the shell? so, that I get only the output from the node console statement.