Popen3 + bash surprise

It was surprising when the following code froze:

require 'open3'
i, o, e = Open3::popen3('/bin/bash')
c = o.getc
puts c.chr # expecting the first character of my bash prompt

···

--
--------------------------------------------
Aleksandr Levchuk
University of California, Riverside
1-951-368-0004
--------------------------------------------

man bash: it behaves differently depending on whether it's a login shell or
not and whether connected to a tty or not. you may want to try out my session
lib

   harp:~ > cat a.rb
   require 'rubygems' # gem install session - http://rubyforge.org/projects/codeforpeople/
   require 'session'

   bash = Session::Bash.new

   stdout, stderr = bash.execute 'export a=42'

   stdout, stderr = bash.execute 'echo $a'
   puts stdout

   bash.execute 'date', :stdout => STDOUT

   harp:~ > ruby a.rb
   42
   Tue Jan 9 08:00:47 MST 2007

regards.

-a

···

On Tue, 9 Jan 2007, Aleksandr Levchuk wrote:

It was surprising when the following code froze:

require 'open3'
i, o, e = Open3::popen3('/bin/bash')
c = o.getc
puts c.chr # expecting the first character of my bash prompt

--
in the practice of tolerance, one's enemy is the best teacher.
- the dalai lama