• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Capturing Script Output (jsr223)

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic