unknown wrote:
> On Wed, 24 May 2006, Geoff Stanley wrote:
> 
>>        irb.gets        # Gets the line that we just put.
>> basic things like '1+2' and 'foo = 42', but for a multiline piece of
>> code, such as a method definition, it breaks down:
>>    >> def foo
>>       puts "bar"
>>    end
>>    foo
>>    ....... hello?
>> As you can see, I got no output back.
>>
>> Any way popen could be used more effectively? I don't want to have to
>> reimplement irb -- that would be a lot of work, I imagine.
> 
> you are trying way to hard:
> 
>    harp:~ > cat a.rb
>    system 'irb'
>    puts 'done'
> 
> 
>    harp:~ > ruby a.rb
>    irb(main):001:0> def foo
>    irb(main):002:1> 42
>    irb(main):003:1> end
>    => nil
>    irb(main):004:0> foo
>    => 42
>    irb(main):005:0> exit
>    done
> 
> irb uses readline so you need to use pty to control it.  otherwise 
> you'll not
> see the prompt.
> 
> -a

Starting an irb session within a program is pretty easy. But it's not 
what I want. I need to send a line to irb and receive the output. 
(Actually, it would be best if I could receive what the 'input' line 
looks like -- "irb(main):006:0> foo = 5" or the like. I don't know even 
if piping can do this.

I was looking at the FXIRB code (http://rubyforge.org/projects/fxirb/) 
and it seems they've had to go to quite a great length to do it.

-- 
Posted via http://www.ruby-forum.com/.