[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Getting pipe return codes from SYSTEM command

Russell Quinn

5/7/2008 3:34:00 PM

I'm trying to find the return codes from bash for piped commands. i.e.

system("ls")

puts("#{$?.exitstatus}")

This returns the return code of ls

system("ls | bzip2 -c > ./out.txt")

how can I still get the return code of ls?

Thanks,

Russell.
--
Posted via http://www.ruby-....

18 Answers

ara.t.howard

5/7/2008 3:45:00 PM

0


On May 7, 2008, at 9:33 AM, Russell Quinn wrote:
> how can I still get the return code of ls?

you cannot. this is a bash limitation.

if you need to do that use something like:


stdout = IO.popen('ls'){|pipe| pipe.read}

p $?.exitstatus

stdout = IO.popen('bzip2 -c', 'r+'){|pipe| pipe.write stdout;
pipe.close_write; pipe.read}

p $?.exitstatus

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




Russell Quinn

5/7/2008 3:50:00 PM

0

Thanks for the reply. But there is a pipestatus array in bash isn't
there?

ls | foo

echo ${PIPESTATUS[0]}

see:
http://aplawrence.com/Blog...

I just couldn't get it to work from Ruby
--
Posted via http://www.ruby-....

Albert Schlef

5/7/2008 3:56:00 PM

0

>
> system("ls | bzip2 -c > ./out.txt")
>
> how can I still get the return code of ls?
>

If you're using bash then it has an shell variable that records the exit
status of all commands in a pipeline (it's an array). Do 'man bash'.
--
Posted via http://www.ruby-....

Albert Schlef

5/7/2008 4:17:00 PM

0

Russell Quinn wrote:
> ls | foo
>
> echo ${PIPESTATUS[0]}
>
> I just couldn't get it to work from Ruby

try 'ls | echo; exit ${PIPESTATUS[0]}'
--
Posted via http://www.ruby-....

ara.t.howard

5/7/2008 4:32:00 PM

0


On May 7, 2008, at 9:50 AM, Russell Quinn wrote:
> Thanks for the reply. But there is a pipestatus array in bash isn't
> there?
>
> ls | foo
>
> echo ${PIPESTATUS[0]}
>
> see:
> http://aplawrence.com/Blog...
>
> I just couldn't get it to work from Ruby
> --


that's because you've lost the bash process by the time bash exits.
use my session gem if you want a persistent bash session against which
to run commands:

require 'session'

bash = Session::Bash.new

stdout, stderr = bash.execute 'ls | grep something'
p bash.status

stdout, stderr = bash.execute 'echo ${PIPESTATUS[0]}'
p bash.status

etc. session uses a *single* bash session for all it's commands so
you can do this sort of thing. however i'm not sure what the point is
when pipelining from ruby, without shelling out, is so easy?

regards.

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




Russell Quinn

5/7/2008 4:53:00 PM

0


> try 'ls | echo; exit ${PIPESTATUS[0]}'

Magical! thanks :)
--
Posted via http://www.ruby-....

Alan Ferris

6/24/2012 6:18:00 PM

0

On Sat, 23 Jun 2012 19:12:00 -0700, Rockinghorse Winner
<badass.superman@gmx.com> wrote:

>>> >> You seem more interested in semantics than you are the fact that babies
>>> >> ( yes, babies ) are being slaughtered in the most gruesome, painful manner.
>>
>> Pretending a fetus is a baby does not make it one.
>>
>> In Jewish practice, and in many other cultures, a fetus does not become
>> a baby until it draws its first breath.
>> --
>> "Ignorance is preferable to error, and he is less
>> remote from the- truth who believes nothing than
>> he who believes what is wrong.
>> Thomas Jefferson
>
>In Judaism, as in most religions, abortion for convenience is considered
>sinful.

How do you define convenience?
--
Ferrit

()'.'.'()
( (T) )
( ) . ( )
(")_(")

Syd M.

6/24/2012 7:03:00 PM

0

On Jun 24, 2:17 pm, Alan Ferris <hairy.fer...@yahoo.co.uk> wrote:
> On Sat, 23 Jun 2012 19:12:00 -0700, Rockinghorse Winner
>
>
>
>
>
>
>
>
>
> <badass.super...@gmx.com> wrote:
> >>> >> You seem more interested in semantics than you are the fact that babies
> >>> >> ( yes, babies ) are being slaughtered in the most gruesome, painful manner.
>
> >> Pretending a fetus is a baby does not make it one.
>
> >> In Jewish practice, and in many other cultures, a fetus does not become
> >> a baby until it draws its first breath.
> >> --
> >> "Ignorance is preferable to error, and he is less
> >>  remote from the- truth who believes nothing than
> >> he who believes what is wrong.
> >>                      Thomas Jefferson
>
> >In Judaism, as in most religions, abortion for convenience is considered
> >sinful.
>
> How do you define convenience?

Anything other then just going along and having the kid, no matter her
circumstance.

Alan Ferris

6/24/2012 7:58:00 PM

0

On Sun, 24 Jun 2012 12:02:51 -0700 (PDT), "Syd M."
<pauldavidwright@yahoo.com> wrote:

>On Jun 24, 2:17?pm, Alan Ferris <hairy.fer...@yahoo.co.uk> wrote:
>> On Sat, 23 Jun 2012 19:12:00 -0700, Rockinghorse Winner
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> <badass.super...@gmx.com> wrote:
>> >>> >> You seem more interested in semantics than you are the fact that babies
>> >>> >> ( yes, babies ) are being slaughtered in the most gruesome, painful manner.
>>
>> >> Pretending a fetus is a baby does not make it one.
>>
>> >> In Jewish practice, and in many other cultures, a fetus does not become
>> >> a baby until it draws its first breath.
>> >> --
>> >> "Ignorance is preferable to error, and he is less
>> >> ?remote from the- truth who believes nothing than
>> >> he who believes what is wrong.
>> >> ? ? ? ? ? ? ? ? ? ? ?Thomas Jefferson
>>
>> >In Judaism, as in most religions, abortion for convenience is considered
>> >sinful.
>>
>> How do you define convenience?
>
>Anything other then just going along and having the kid, no matter her
>circumstance.

It is usual for those who oppose abortion to try and change the normal
usage of the English language to support their views.

--
Ferrit

()'.'.'()
( (T) )
( ) . ( )
(")_(")

elizabeth

6/24/2012 11:13:00 PM

0

On Jun 24, 7:35 am, Rockinghorse Winner <badass.super...@gmx.com>
wrote:
> * It may have been the liquor talking, but
>
>
>
>
>
> SkyEyes <skyey...@cox.net> wrote:
> > On Jun 23, 7:12?pm, Rockinghorse Winner <badass.super...@gmx.com>
> > wrote:
> >> * It may have been the liquor talking, but
>
> >> Uergil <Uer...@uer.net> wrote:
> >> > In article <slrnju57de.8n0.badass.super...@badass.edu>,
> >> > ?Rockinghorse Winner <badass.super...@gmx.com> wrote:
>
> >> >> >> You seem more interested in semantics than you are the fact that babies
> >> >> >> ( yes, babies ) are being slaughtered in the most gruesome, painful manner.
>
> >> > Pretending a fetus is a baby does not make it one.
>
> >> > In Jewish practice, and in many other cultures, a fetus does not become
> >> > a baby until it draws its first breath.
> >> > --
> >> > "Ignorance is preferable to error, and he is less
> >> > ?remote from the- truth who believes nothing than
> >> > he who believes what is wrong.
> >> > ? ? ? ? ? ? ? ? ? ? ?Thomas Jefferson
>
> >> In Judaism, as in most religions, abortion for convenience is considered
> >> sinful.
>
> > Actually, in Judaism, it isn't.  Besides, saying that women have
> > abortions for "convenience" is a put-down of the life-altering aspects
> > of motherhood.  No woman has an abortion for convenience, they have
> > them because they don't want a particular kid, or *any* kid.  This is
> > a decision that only the mother, in consultation with her doctor (and,
> > if she wishes, her partner), can make.  All conceptions don't have to
> > come to term.
>
> Orthodox judaism certainly does. Reform prolly doesn't, and I don't know
> about Conservative. I understand that the Jewish view doesn't consider
> abortion murder, but it does consider it a sin. Here is the Wiki on this
> subject, and you can draw your own conclusions:
>
> http://en.wikipedia.org/wiki/Judaism_an...
>
> As for who gets to make the decision, ultimately it is the mother's to make.
> However, this would be so whether or not Roe v Wade was law. Ultimately,
> every single person is responsible for every moral action that they take -
> that is not a liberal position  but the nature of being a free moral agent,
> i.e. human.
>
>
>
> > Brenda Nelson, A.A.#34
> > BAAWA Knight of the Golden Litterbox
> > EAC Professor of Feline Thermometrics and Cat-Herding
> > skyeyes nine at cox dot net OR
> > skyeyes nine at yahoo dot com
>
> Terry
> --
> "For I would ride with you upon the wind,    |/
> Run on the top of the dishevelled tide,      |/    Gentoo Linux
> And dance upon the mountains like a flame."  |/
>     -Yeats                                   |/- Hide quoted text -
>
> - Show quoted text -

Nope.
Abortion is not a sin in anyone's bible.