Thanks. I did look at that, and it gives some answers and raises some
more questions.
Now the pressing issue is how I can capture all the output of the Ruby
script. (Imagine a GUI-based command shell that needs to be able to
snag all the console IO of the Ruby script.) There are some initial
thoughts about this in the embedding tutorial at ruby embedded into c++ .
Would it be possible to inject an overload for IO#write or somesuch
from the C program into Ruby before the script runs? If so, how could
I do that? Otherwise, I might have to make a special build of Ruby to
do callbacks into the app, and that's not nice.
This method won't capture everything (e.g. if the script calls external
programs or uses other more devious means of writing to stdout/err), but
consider:
irb(main):001:0> require 'stringio'
=> true
irb(main):002:0> s = StringIO.new
=> #<StringIO:0x4031ac7c>
irb(main):003:0> $stderr = s
=> #<StringIO:0x4031ac7c>
irb(main):004:0> $stderr.puts "This is a test"
=> nil
irb(main):009:0> s.string
=> "This is a test\n"
Otherwise you must use a dup2 or a similar mechanism to redirect output to a
pipe or a socket.
Paul
···
On Fri, Sep 02, 2005 at 02:56:24AM +0900, Timothy Byrd wrote:
Now the pressing issue is how I can capture all the output of the Ruby
script.