[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

popen3 mysteriously hangs

James Dinkel

9/26/2008 4:19:00 PM

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
--
Posted via http://www.ruby-....

4 Answers

ara.t.howard

9/26/2008 5:22:00 PM

0


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://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




James Dinkel

9/26/2008 6:59:00 PM

0

Ara Howard wrote:
>
> 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.
--
Posted via http://www.ruby-....

ara.t.howard

9/26/2008 7:23:00 PM

0


On Sep 26, 2008, at 12:58 PM, James Dinkel wrote:

> Ara Howard wrote:
>>
>> 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.
> --
> Posted via http://www.ruby-....
>

cool. my example was wrong too

status, stdout, stderr = systemu command

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




James Dinkel

9/26/2008 7:25:00 PM

0

Ara Howard wrote:
>
> 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
--
Posted via http://www.ruby-....