Realtime display of stdout while using Kernel::backtick

Hello,

I am using Ruby to develop an automatic build script at my company. We do
embedded development, and have three code bases that get built and nested
inside each other. (microcontrollers booting dsps in the box, and a GUI that
can update the box’s code)

So far the script is working great. If does just what I need, and the other
developers are impressed with the flexibility of the language. I have only
one problem: When I use the backtick operator (actually %x{}) I can capture
that stdout output, but I can’t display it in real time (as the external
program prints it)

I am doing something like this:

puts(%x{#{some_compilicated_pvcs_command_string}})

This drives PVCS quite well. It checks out all ( >200) my files and prints a
message listing each file that it checks out. Unfortunately, all the text
spews out at once! When the tool is invoked directly from the command line,
the text comes one line at a time, synchronous with the checkouts.

I am running the very impressive Win32 distribution (version 1.6.8-8) from
the Pragmatic Programmer site.

Is there a way to set up Ruby to send the output of the tool to the console
as it comes in? Any advice would be greatly appreciated!

This is a fantastic language. I can’t wait to do more with it!

Kevin M.

Don’t use the backticks. Use IO.popen instead. Someone else can elaborate on
what’s required to get this working right under Windows…

Tim Bates

···

On Thu, 30 Jan 2003 03:31 pm, Kevin Moore wrote:

Is there a way to set up Ruby to send the output of the tool to the console
as it comes in? Any advice would be greatly appreciated!


tim@bates.id.au

> Is there a way to set up Ruby to send the output of the tool to the console > as it comes in? Any advice would be greatly appreciated! This may help: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/18771
···

On Thu, 30 Jan 2003 14:01:00 +0900 “Kevin Moore” kgm_lists@ameritech.net wrote:

This is a fantastic language. I can’t wait to do more with it!

Kevin M.


Daniel P. Zepeda

Many ways to execute a shell-command

STDOUT.sync = true

cmd = ‘ping -n 5 localhost’
#‘osql -Usa -Pdbmteam -S EMACHINE -d master -Q"select * from
sysobjects" -n -h-1 -w 1000’

method 1

open(“|#{cmd}”) do |f|
f.each{|line| print line}
end

method 2

system(“#{cmd}”)

method 3

puts #{cmd}

method 4

IO.popen(cmd) do |p|
p.each do |line|
puts line
end
end

“Kevin Moore” kgm_lists@ameritech.net wrote in message
news:hQ1_9.398$dL4.323583@newssrv26.news.prodigy.com

Hello,

I am using Ruby to develop an automatic build script at my company. We do
embedded development, and have three code bases that get built and nested
inside each other. (microcontrollers booting dsps in the box, and a GUI
that
can update the box’s code)

So far the script is working great. If does just what I need, and the
other
developers are impressed with the flexibility of the language. I have only
one problem: When I use the backtick operator (actually %x{}) I can
capture
that stdout output, but I can’t display it in real time (as the external
program prints it)

I am doing something like this:

puts(%x{#{some_compilicated_pvcs_command_string}})

This drives PVCS quite well. It checks out all ( >200) my files and prints
a
message listing each file that it checks out. Unfortunately, all the text
spews out at once! When the tool is invoked directly from the command
line,
the text comes one line at a time, synchronous with the checkouts.

I am running the very impressive Win32 distribution (version 1.6.8-8)
from
the Pragmatic Programmer site.

Is there a way to set up Ruby to send the output of the tool to the
console

···

as it comes in? Any advice would be greatly appreciated!

This is a fantastic language. I can’t wait to do more with it!

Kevin M.