From: Steve Johnston Date: 2012-01-11T07:58:21+09:00 Subject: 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 executing. Now I am trying to use a gem called "Session", which has very little documenation. 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. ---- #!/usr/local/bin/ruby $:.unshift '.', '..', 'lib', File.join('..','lib') require 'session' sh = Session::new stdout, stderr = sh.execute 'perl5.8.5 /home/test/perl2.ruby.pl' 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' #!/usr/local/bin/ruby $:.unshift '.', '..', 'lib', File.join('..','lib') require 'session' bash = Session::Bash.new stdout, stderr = StringIO::new, StringIO::new bash.execute 'perl5.8.5 /home/test.perl2.ruby.pl', :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 -- Posted via http://www.ruby-forum.com/.