On Sep 26, 2008, at 10:19 AM, James Dinkel wrote:

> I'm having a problem with a popen3 inexplicably hanging.  I'm trying  
> to
> run the rpmbuild command to automate compiling some srpms, as you'll  
> see
> below.  For most srpms, the script runs through just fine.  Here's the
> relevant popen3 block:
>
> --------------------------
> Open3.popen3("rpmbuild --rebuild GConf2-2.14.0-9.el5.src.rpm") do
> |stdin, stdout, stderr|
>  if stderr.read.split($/)[-1] == '+ exit 0'
>    success = true
>    output_files = get_output_files(stdout.read)
>  end
> end
> --------------------------
>
> This is on RedHat Enterprise Linux 5.0, using ruby 1.8.5 (2006-08-25).
> I've ran "rpmbuild --rebuild GConf2-2.14.0-9.el5.src.rpm" directly  
> from
> the command line and it completes just fine in about 2 minutes.
>
> A couple notes, "GConf2-2.14.0-9.el5.src.rpm" would normally be filled
> in by a variable, but GConf2-2.14.0-9.el5.src.rpm is one of the srpms
> that hang the system.  Also, get_output_files() is my own method  
> which I
> would suspect as hanging, but binaries from the rpmbuild are never
> created, so it must never even make to that point.
>
> Any help troubleshooting this would be appreciated, or maybe someone
> knows of a better way to run this command and capture stdout and  
> stderr.
>
> Thanks,
>
> James

you are clogging the buffer with stdout and so the child process goes  
to sleep.  you have to use some caution getting both stdout and stderr  
from a child process because a full buffer for either will block the  
child.  probably the simplest way to do what you want is

   gem install systemu


   stdout, stderr, status = systemu command


this also works on windows  if you need to handle the output in  
realtime try using open4 (gem install open4) as it abstracts that  
threaded reading for you.

cheers.


a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being  
better. simply reflect on that.
h.h. the 14th dalai lama