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.
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.
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.
I don’t need realtime output, I just need the output when it’s all done.
Is there any way to flush stdout and stderr while the program is
running? I really only need the last 50 lines or so of stdout and only
the very last line of stderr.
Is there any way to flush stdout and stderr while the program is
running? I really only need the last 50 lines or so of stdout and
only
the very last line of stderr.
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.
Some quick irb testing looks like systemu is going to work great. Just
a quick note, though: the variables are out of order, it looks like it
should be
status, stdout, stderr = systemu command
Thanks again!
James
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.