# Popen3 + bash surprise

**URL:** <https://www.ruby-forum.com/t/popen3-bash-surprise/81478>\
**Category:** Ruby\
**Created:** [January 9, 2007, 8:32am UTC](https://www.ruby-forum.com/t/popen3-bash-surprise/81478 "2007-01-09T08:32:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleksandr\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@Aleksandr\_L](https://www.ruby-forum.com/u/Aleksandr_L)\
**Post date:** [January 9, 2007, 8:32am UTC](https://www.ruby-forum.com/t/popen3-bash-surprise/81478/1 "2007-01-09T08:32:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aleksandr\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@Aleksandr\_L](https://www.ruby-forum.com/u/Aleksandr_L)\
**Post date:** [January 9, 2007, 4:02pm UTC](https://www.ruby-forum.com/t/popen3-bash-surprise/81478/2 "2007-01-09T16:02:51Z")

</div>

On Tue, 9 Jan 2007, Aleksandr L. 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/](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
