[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

getstatusoutput

OliverMarchand

10/6/2006 1:01:00 PM

Dear Ruby fellows,

I am desperately trying to write a quite simple function (something
similar to what I was acumstomed to with Python)

status, stdout, stderr = getstatusoutput(somecmdstring)

status is an integer, stdout and stderr are strings

Now in principle I know how to write such a function, but I don't know
what the best interface to spawn the process given in somecmdstring is.
Here is my analysis of the situation:

IO::popen --- mixes stdout and stderr
Open3.popen3 --- no possibility to wait for the process to finish
exec --- I would have to write "everything" by myself, double fork,
etc.
....popen4 --- not a standard function

Is my analysis right, or is there something I am not understanding
about open3?

thanks for any help,
Oliver

3 Answers

Ara.T.Howard

10/6/2006 1:36:00 PM

0

OliverMarchand

10/6/2006 4:17:00 PM

0

ara.t.howard@noaa.gov schrieb:
> your analysis is correct, it's why i wrote open4. however, you cannot wait on
> the program with 'getstatusoutput' either - at least i don't see the child pid
> in there?
>
> do you mean you just need the exit_status? i assume so given the interface
> above.

Thanks for your quick answer.

I was assuming that my getstatusoutput returns after the process has
finished. I was wanting to add a timeout parameter and an exception for
overly long executions, but left that discussion out of the original
post to make it as simple as possible.

Thanks for hinting open4, the only thing I am wondering is the best
method to wait for pid to finish!? Now I can write some "while pid
exists do nothing", but doen't that consume unnecessary cyles?

Thanks, Oliver

Ara.T.Howard

10/6/2006 4:39:00 PM

0