@Override
    public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) {
        InputStream xin =
                (in == null)
                        ? System.in
                        : in;
        PrintStream xout =
                (out == null)
                        ? System.out
                        : (out instanceof PrintStream)
                                ? (PrintStream) out
                                : new PrintStream(out);
        PrintStream xerr =
                (err == null)
                        ? System.err
                        : (err instanceof PrintStream)
                                ? (PrintStream) err
                                : new PrintStream(err);
        try {
            JavaShellToolBuilder
                    .builder()
                    .in(xin, null)
                    .out(xout)
                    .err(xerr)
                    .run(arguments);
            return 0;
        } catch (Throwable ex) {
            xerr.println(ex.getMessage());
            return 1;
        }
    }
@ Override public int run ( InputStream in , OutputStream out , OutputStream err , String ... arguments ) { InputStream xin = ( in == null ) ? System . in : in ; PrintStream xout = ( out == null ) ? System . out : ( out instanceof PrintStream ) ? ( PrintStream ) out : new PrintStream ( out ) ; PrintStream xerr = ( err == null ) ? System . err : ( err instanceof PrintStream ) ? ( PrintStream ) err : new PrintStream ( err ) ; try { JavaShellToolBuilder . builder ( ) . in ( xin , null ) . out ( xout ) . err ( xerr ) . run ( arguments ) ; return 0 ; } catch ( Throwable ex ) { xerr . println ( ex . getMessage ( ) ) ; return 1 ; } }
Run the jshell tool.  The streams {@code out} and {@code err} are
converted to {@code PrintStream} if they are not already.
Any {@code Exception} is caught, printed and results in a non-zero return.

@param in command line input (snippets and commands), and execution
"standard" input; use System.in if null
@param out command line output, feedback including errors, and execution
"standard" output; use System.out if null
@param err start-up errors and execution "standard" error; use System.err
if null
@param arguments arguments to pass to the tool
@return 0 for success; nonzero otherwise
@throws NullPointerException if the array of arguments contains
any {@code null} elements.