aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "Capturing Script Output (jsr223)" Watch "Capturing Script Output (jsr223)" New topic
Author

Capturing Script Output (jsr223)

John Bartlett
Ranch Hand

Joined: Jan 25, 2006
Posts: 116
Hi,

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
puts('hello')
end
hello

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,

John
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
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).


Ping & DNS - my free Android networking tools app
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?

[EDIT]

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?

[/EDIT]

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: http://aspose.com/file-tools
 
subject: Capturing Script Output (jsr223)