[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Is there something built-in for this ?

Thibaut Barrère

2/5/2009 1:51:00 PM

Hi,

very often I use this method:

def launch(cmd)
raise "Error launching #{cmd}" unless system(cmd)
end

Is there a built-in equivalent ?

cheers,

-- Thibaut
4 Answers

aldric[removeme]

2/6/2009 2:51:00 PM

0

Thibaut Barrère wrote:
> Hi,
>
> very often I use this method:
>
> def launch(cmd)
> raise "Error launching #{cmd}" unless system(cmd)
> end
>
> Is there a built-in equivalent ?
>
> cheers,
>
> -- Thibaut
>
begin
system(cmd)
rescue NameError => e
puts e
end

.... Does that help you ?

--Aldric

Thibaut Barrère

2/7/2009 4:02:00 PM

0

> begin
>   system(cmd)
> rescue NameError => e
>   puts e
> end
>
> ... Does that help you ?

hum -- not sure actually. Is system() supposed to raise a NameError ?
I didn't see this mentioned in the docs.

I searched further yet could not find anything like launch() so far.

-- Thibaut

aldric[removeme]

2/8/2009 3:40:00 AM

0

Thibaut Barrère wrote:
>> begin
>> system(cmd)
>> rescue NameError => e
>> puts e
>> end
>>
>> ... Does that help you ?
>>
>
> hum -- not sure actually. Is system() supposed to raise a NameError ?
> I didn't see this mentioned in the docs.
>
> I searched further yet could not find anything like launch() so far.
>
> -- Thibaut
>
I have no idea.. I just started a shell, made up a command name which I
knew didn't exist, and waited to see what came back.
Reading your original post again, I think it's not quite what you want...

7stud --

2/8/2009 12:14:00 PM

0

Thibaut Barrère wrote:
>> begin
>> � system(cmd)
>> rescue NameError => e
>> � puts e
>> end
>>
>> ... Does that help you ?
>
> hum -- not sure actually. Is system() supposed to raise a NameError ?
> I didn't see this mentioned in the docs.
>

Easy enough to test:

begin
result = system("made up command")
puts result
rescue NameError => e
puts e
end

--output:--
false

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