From: "Ara.T.Howard" Date: 2005-10-14T01:21:55+09:00 Subject: Re: exec and pipe On Fri, 14 Oct 2005, ientu wrote: > I think IO.popen waits for the process to terminate before putting any > data into the pipe. This doesn't work for me, as I have to process the > output in real time. that's what popen is for: harp:~ > cat a.rb STDOUT.sync = true and loop{ sleep 0.42 and puts Time::now } harp:~ > cat b.rb IO::popen('ruby a.rb'){|pipe| loop{ print pipe.gets }} harp:~ > ruby b.rb Thu Oct 13 09:58:03 MDT 2005 Thu Oct 13 09:58:03 MDT 2005 Thu Oct 13 09:58:04 MDT 2005 Thu Oct 13 09:58:04 MDT 2005 Thu Oct 13 09:58:04 MDT 2005 Thu Oct 13 09:58:05 MDT 2005 Thu Oct 13 09:58:05 MDT 2005 Thu Oct 13 09:58:06 MDT 2005 Thu Oct 13 09:58:06 MDT 2005 Thu Oct 13 09:58:07 MDT 2005 Thu Oct 13 09:58:07 MDT 2005 Thu Oct 13 09:58:07 MDT 2005 Thu Oct 13 09:58:08 MDT 2005 Thu Oct 13 09:58:08 MDT 2005 Thu Oct 13 09:58:09 MDT 2005 ... ... ... perhaps your perl code is buffering output. make sure the stdout of the perl process is not fully buffered. programs are, by default, fully buffered when run into a pipe. you can 'fix' broken code by creating a wrapper that does #! /usr/bin/env ruby STDOUT.sync = true exec(ARGV.join(' ')) and running all code, including perl code, under this wrapper. so IO::popen('wrapper a.pl'){|pipe| loop{ print pipe.gets }} hth. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | Your life dwells amoung the causes of death | Like a lamp standing in a strong breeze. --Nagarjuna ===============================================================================