System command expansion after PTY.spawn

Hi!

-------------------------
require 'pty’
require ‘expect’

pty_read, pty_write, pid = PTY.spawn( “irb” )
pty_write.sync = true
pty_read.expect( "irb(main):001:0> " )
pty_write.print( “exit\n” )
pty_read.close
pty_write.close

uname
-------------------------

results in

-------------------------
t.rb:11:in ``’: Child_changed: 29977 (RuntimeError)
from t.rb:11
-------------------------

Please, what am I missing here?

Thanks,

···


chris

Sorry, i forgot: This happens with ruby 1.6.8 on Intel Solaris 5.8.

···

On Thu, Mar 06, 2003 at 01:56:39AM +0900, Christian von Mueffling wrote:

Please, what am I missing here?


chris

Please, what am I missing here?

Nothing, pty seems have a problem : if someone know well this, he can
perhaps look at it.

Guy Decoux

Hi,

···

At Thu, 6 Mar 2003 01:56:39 +0900, Christian von Mueffling wrote:

t.rb:11:in ``': Child_changed: 29977 (RuntimeError)
from t.rb:11

Exception to notice that the child process exited.


Nobu Nakada

Exception to notice that the child process exited.

OK, but now you really think that this is normal ?

pigeon% cat b.rb
#!/usr/bin/ruby
require 'pty'
require 'expect'

pty_read, pty_write, pid = PTY.spawn( "irb" )
p pid
pty_write.sync = true
pty_read.expect( "irb(main):001:0> " )
pty_write.print( "exit\n" )
pty_read.close
pty_write.close
10000.times {}
pigeon%

pigeon% b.rb
25521
./b.rb:12:in `times': Child_changed: 25521 (RuntimeError)
        from ./b.rb:12
pigeon%

and it exist other problems

Guy Decoux

Hi,

Exception to notice that the child process exited.

OK, but now you really think that this is normal ?

It may not be easy to use. I don’t know from where this design
has come.

and it exist other problems

What problems?

···

At Thu, 6 Mar 2003 22:06:36 +0900, ts wrote:


Nobu Nakada

You can even make this smaller:

----------
require ‘pty’
pty_read, pty_write, pid = PTY.spawn( “irb” )
uname
----------

This results in

----------
t.rb:3:in ``': fork: 5158 (RuntimeError)
from t.rb:3
----------

:-((

···

On Thu, Mar 06, 2003 at 10:06:36PM +0900, ts wrote:

Exception to notice that the child process exited.
OK, but now you really think that this is normal ?


chris

It may not be easy to use. I don't know from where this design
has come.

The signal was installed by pty, if it can't manage this signal it must
*not* install it

What problems?

pigeon% cat b.rb
#!/usr/bin/ruby
require 'pty'
require 'expect'

24.times do
   PTY.spawn( "irb" ) do |pty_read, pty_write|
      pty_write.sync = true
      pty_read.expect( "irb(main):001:0> " )
      pty_write.print( "exit\n" )
   end
end
pigeon%

pigeon% b.rb
./b.rb:6:in `spawn': Too many ptys are open (RuntimeError)
        from ./b.rb:6
        from ./b.rb:5:in `times'
        from ./b.rb:5
pigeon%

Manifestly it can't manage this signal

Guy Decoux

require 'pty'
pty_read, pty_write, pid = PTY.spawn( "irb" )
`uname`

Well, normally this must be written

pigeon% cat b.rb
#!/usr/bin/ruby
require 'pty'
pty_read, pty_write, pid = PTY.spawn( "irb" )
PTY.protect_signal do
   p `uname`
end
pigeon%

pigeon% b.rb
"Linux\n"
pigeon%

Guy Decoux

Hi,

···

In message “Re: system command expansion after PTY.spawn” on 03/03/06, Christian von Mueffling cvm@aiss.de writes:

require ‘pty’
pty_read, pty_write, pid = PTY.spawn( “irb” )
uname

This works with 1.8.

						matz.

But i get still strange things here:

----------------------------------------------
require ‘pty’
require ‘expect’

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:

require ‘pty’
pty_read, pty_write, pid = PTY.spawn( “irb” )
uname

This works with 1.8.


chris

Hi,

But i get still strange things here:

----------------------------------------------
require ‘pty’
require ‘expect’

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:

[…]

Cool, that works. :slight_smile: Just retrying once seems to do want I want :slight_smile:

Thanks very much!

···

On Fri, Mar 07, 2003 at 02:46:17AM +0900, Yukihiro Matsumoto wrote:

I think it’s the original design by A.Ito, the author of pty. You
have to protect PTY.spawn like:


chris