popen3 + bash surprise

  • Thread starter Aleksandr Levchuk
  • Start date
A

Aleksandr Levchuk

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


--
 
A

ara.t.howard

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,835
Members
47,383
Latest member
EzraGiffor

Latest Threads

Top