• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Capturing Script Output (jsr223)

 
John Bartlett
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic