popen3 mysteriously hangs

J

James Dinkel

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
 
A

ara.t.howard

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/
 
J

James Dinkel

Ara said:
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.

I'll have a look at systemu, too. Thanks.
 
A

ara.t.howard

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.

I'll have a look at systemu, too. Thanks.

cool. my example was wrong too

status, stdout, stderr = systemu command

a @ http://codeforpeople.com/
 
J

James Dinkel

Ara said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top