Forum: Ruby popen3 + bash surprise

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4b7e8a3c6104cebef96f884625fba65a?d=identicon&s=25 Aleksandr Levchuk (Guest)
on 2007-01-09 08:32
(Received via mailing list)
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
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2007-01-09 16:02
(Received via mailing list)
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

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
This topic is locked and can not be replied to.