I want to run a JavaScript code snippet which returns boolean, from java.
Currently I am using ProcessBuilder
to run the JavaScript program with the command jjs filename
.
I am able to perform the operations and getting the output from getOutputStream
properly.
But my requirement is to return boolean from the script, when I make the similar changes in the script it gives compile time error invalid return statement, which is obvious.
when I use
var a=5; var b=6; print(a+b);
I am getting a output 11. But I want to execute a script like
var a=5;
if(a>0)
return true;
else
return false;
I get errorStream like Invalid return statement Expected eof but found } } ^
The getInputStream method of the ProcessBuilder class gives you a stream from which you can read bytes. You have to convert the bytes to String and then parse to boolean.