I use Nashorn scripts from a Java application. Java sets the context (including errorWriter) and everything just works fine... BUT i haven't found the way to write to the error Stream from the nashorn script. Does anyone know ?
I tried to throw an error but it outputs in the scriptException, not in the error output Stream.
Thanks for any idea.
It looks like there is no built in function to write to
stderr, like there is one to write tostdout(print).But, you can set an attribute in the ScriptContext that has a function to write to it's error writer.
The reason to do it this way, instead of binding the error writer object directly, is that you can still change the error writer later, and it will still work.
Afterwards you could do this:
Which will write all the errors to the Java
stderr(which is not the default btw).Then from javascript you can do: