File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Languages and the fly likes Capturing Script Output (jsr223) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "Capturing Script Output (jsr223)" Watch "Capturing Script Output (jsr223)" New topic

Capturing Script Output (jsr223)

John Bartlett
Ranch Hand

Joined: Jan 25, 2006
Posts: 116

I am using jsr223 to compile scripts custom made in a swing application.

Everything is working fine however it would be nice to display the output of the scripts to the user, as currently the output is just being shown in the console.

e.g user creates very simple script in jruby

def fun

this will output hello, but the ran output goes directly to the console when I would like to output it via my swing application.

I have googled around and for some reason cannot find anything on this topic, is it possible to capture the output? or to tell it to output somewhere else?

Any help would be greatly appreciated.

Thank you,

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
ScriptContext has a setWriter method with which you can send script output anywhere you like (e.g. a StringWriter which you can then use to display the output in the GUI).
John Bartlett
Ranch Hand

Joined: Jan 25, 2006
Posts: 116
Hi Ulf thank you for the reply however I dont seem to be getting the desired results.

This is the code I have for evaluating the script file:

However when i inspect the writer afterwards it is empty, while an output is still being shown in the console. Any ideas y that is?


I have just found out that this works fine with the JRuby engine, but the problem explained above happens when I use the javascript engine. Any ideas why the JRuby one works with this writer but javascript one doesnt?


p.s ignore spelling mistakes in code just done to avoid problems adding to post due to filter
[ March 24, 2008: Message edited by: John Bartlett ]
I agree. Here's the link:
subject: Capturing Script Output (jsr223)
It's not a secret anymore!