Session Gem: How to get line-by-line output from shell script using

Thanks in advance for your help! I need line-by-line output from a bash
script from inside ruby (and ultimately, rails). So far, all I can get
using IO.popen or backticks, is the output after the script has finished

Now I am trying to use a gem called “Session”, which has very little

The first code example below produces the output all at once, even
though the perl script flushes its buffer with every line ($|) and when
it runs in bash, updates the screen often.

$:.unshift ‘.’, ‘…’, ‘lib’, File.join(’…’,‘lib’)
require ‘session’

sh = Session::new

stdout, stderr = sh.execute ‘perl5.8.5 /home/test/’
stdout.each_line{|line| print line}

This second example runs, but it does not print to the screen (stdout)
and I have yet to discover where the output ‘goes’

$:.unshift ‘.’, ‘…’, ‘lib’, File.join(’…’,‘lib’)
require ‘session’

bash =
stdout, stderr = StringIO::new, StringIO::new
bash.execute ‘perl5.8.5 /home/’, :stdout => stdout,
:stderr => stderr
stdout.each_line{|line| print line}
puts bash.exit_status

What I am really working towards is a way to display line-by-line output
from a perl script as it executes in rails. I don’t necessarily need to
use “Session::”. Please let me know if you have a better way, one that
works. Thanks

This works. I run a perl script from ruby, and get line-by-line output
as it runs.

#!/usr/bin/env ruby

readme = IO.popen(“/home/test/”)
while readme.gets do
puts $_

Thanks to