This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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: 43028
76
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic