i, o, pid = PTY.spawn( “irb” )
p pid
puts i.expect( "irb(main):001:0> " )
o.print( “exit\n” )
i.close
o.close
i, o, pid = PTY.spawn( “irb” )
p pid
puts i.expect( "irb(main):001:0> " )
o.print( “exit\n” )
i.close
o.close
----------------------------------------------
This results with ruby 1.8.0 in:
----------------------------------------------
11301
irb(main):001:0>
11303
t.rb:4:in `expect’: pty - exit: 11301 (PTY::ChildExited)
from t.rb:13
----------------------------------------------
and with ruby 1.6.8 in:
----------------------------------------------
11323
irb(main):001:0>
11324
/users/cvm/local/gnu/ruby-1.6.8/lib/ruby/1.6/expect.rb:13:in select': Child_changed: 11323 (RuntimeError) from /users/cvm/local/gnu/ruby-1.6.8/lib/ruby/1.6/expect.rb:13:in expect’
from t.rb:13
----------------------------------------------
It works if i don’t comment out the last 3 lines of each block (but
thenthe processes then are alive until the script ends :-().
Do I use this in a wrong way?
···
On Fri, Mar 07, 2003 at 12:18:20AM +0900, Yukihiro Matsumoto wrote:
i, o, pid = PTY.spawn( “irb” )
p pid
puts i.expect( "irb(main):001:0> " )
o.print( “exit\n” )
i.close
o.close
i, o, pid = PTY.spawn( “irb” )
p pid
puts i.expect( "irb(main):001:0> " )
o.print( “exit\n” )
i.close
o.close
----------------------------------------------
This results with ruby 1.8.0 in:
----------------------------------------------
11301
irb(main):001:0>
11303
t.rb:4:in `expect’: pty - exit: 11301 (PTY::ChildExited)
from t.rb:13
----------------------------------------------
I think it’s the original design by A.Ito, the author of pty.
You have to protect PTY.spawn like:
begin
PTY.spawn( “irb” ) do |i,o,pid|
p pid
puts i.expect( "irb(main):001:0> " )
o.print( “exit\n” )
i.close
o.close
end
rescue
p $!
end
If you want to know the reason of this design, you have to ask him.
I think he still can be reached at the address in the ext/pty/README,
although I haven’t seen him around for a while.
matz.
···
In message “Re: system command expansion after PTY.spawn” on 03/03/07, Christian von Mueffling cvm@aiss.de writes: