0

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.

1 Answer 1

2

It looks like there is a silent option which tells it not to print program-output to console:

shelljs.exec('java -cp bin mypack.Bar', {silent: true}, function (code, output) {
   console.log(output);
});

Take a look at the documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.