[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How to keep proceeding if one command fails (in Rake)????

Luc Vantroys

8/3/2006 1:28:00 PM

Hi All,

Could you tell me how I could do to have rake to run all the tasks no
matter the result of the previous one(s)?

ex:

file 'xxx.c' => ['xxx.h'] do
if(sh(blablabla))
puts "do this"
else
puts "do this"
end

end

When for exemple the sh command failed, it quits and does not run the
rest of the scripts. How can I make this happen?


Thanks,

Luc

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

8 Answers

Matt Todd

8/3/2006 2:28:00 PM

0

Have you looked into using the begin...rescue...end syntax? It's
basically a try/catch (but Ruby doesn't understand the meaning of
'try'.... haha).

begin
sh(blablabla)
puts "do this"
rescue
puts "do this"
end
puts "do this"

That is, if sh() raises an exception. Otherwise, you'd have to

raise "Oops" unless sh(blablala)

Give it a try...

M.T.

Suraj Kurapati

8/4/2006 7:01:00 AM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Matt Todd wrote:
> Have you looked into using the begin...rescue...end syntax? It's
> basically a try/catch (but Ruby doesn't understand the meaning of
> 'try'.... haha).

"Do or do not... there is no try" - Yoda
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFE0vBlmV9O7RYnKMcRAr5qAJ0Suu42JDz2VJdWf3eT8ocbGVNpXQCgmY4D
RGjAeNvqveC4ABmND+h7yAg=
=Bc2D
-----END PGP SIGNATURE-----

Eric Armstrong

8/13/2006 3:23:00 AM

0

On a related note...

When you access ENV or execute a subshell, ruby
gives you a warning if any parent directory in
any part of your search path is world-writable.

Unfortunately, we're talking about system directories
I have no control over, that have to be in my
search path, so that warning gets to be a bit
annoying after a while.

I understand why it's there, but it's even worse
for scripts I distribute: They cause alarm bells
go off, right at the time I'm trying to lull
people to sleep... (Relax... Sleep... Pay no
attention to the ruby under the hood...)

The workaround is to code a semi-colon at the
end of the command, so:

sh "some command;"
or
value = `some command;`

But the unfortunate side effect is that a command
failure gets swallowed as well, and that keeps
Rake from aborting when it rightfully should.

So:
I need a way to make the world-writable
directory warning go away, and at the
same time make sure that Rake sees shell
aborts.

Any solutions out there?



Nobuyoshi Nakada

8/13/2006 8:37:00 AM

0

Hi,

At Sun, 13 Aug 2006 12:23:07 +0900,
Eric Armstrong wrote in [ruby-talk:208107]:
> Unfortunately, we're talking about system directories
> I have no control over, that have to be in my
> search path, so that warning gets to be a bit
> annoying after a while.

World writable system directories? Hmmm..., amazing.

> I understand why it's there, but it's even worse
> for scripts I distribute: They cause alarm bells
> go off, right at the time I'm trying to lull
> people to sleep... (Relax... Sleep... Pay no
> attention to the ruby under the hood...)

def adventurous!
verbose, $VERBOSE = $VERBOSE, nil
yield
ensure
$VERBOSE = verbose
end

adventurous! {system(cmd)}

> The workaround is to code a semi-colon at the
> end of the command, so:
>
> sh "some command;"
> or
> value = `some command;`
>
> But the unfortunate side effect is that a command
> failure gets swallowed as well, and that keeps
> Rake from aborting when it rightfully should.

See $!.success?.

--
Nobu Nakada

Eric Armstrong

8/14/2006 11:14:00 PM

0

Eric Armstrong wrote:
>
> When you access ENV or execute a subshell, ruby
> gives you a warning if any parent directory in
> any part of your search path is world-writable.
> ...
> The workaround is to code a semi-colon at the
> end of the command, so:
>
> sh "some command;"
> or
> value = `some command;`
>
> But the unfortunate side effect is that a command
> failure gets swallowed as well, and that keeps
> Rake from aborting when it rightfully should.
>
It turns out I was (happily) dead wrong about that.
Either of the following work just fine:

if ($? != 0) then
...
exit
end

-or-

require 'English'
if ($CHILD_STATUS != 0) then
...
exit
endif

Eric Armstrong

8/15/2006 12:11:00 AM

0

There's one line in there that's driving me nuts.

nobu@ruby-lang.org wrote:
>
> def adventurous!
> verbose, $VERBOSE = $VERBOSE, nil
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> yield
> ensure
> $VERBOSE = verbose
> end
>
> adventurous! {system(cmd)}
>
What the heck is that line doing??

Hal E. Fulton

8/15/2006 12:25:00 AM

0

Eric Armstrong wrote:
> There's one line in there that's driving me nuts.
>
> nobu@ruby-lang.org wrote:
>
>>
>> def adventurous!
>> verbose, $VERBOSE = $VERBOSE, nil
>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>> yield
>> ensure
>> $VERBOSE = verbose
>> end
>>
>> adventurous! {system(cmd)}
>>
> What the heck is that line doing??


Haha... it's a Perl/Ruby idiom...

x, y = y, x # swap values of x and y

So he was just saving off $VERBOSE so he
could restore it at the end.


Hal



Eric Armstrong

8/15/2006 10:09:00 PM

0

Hal Fulton wrote:
> Eric Armstrong wrote:
>> There's one line in there that's driving me nuts.
>>
>>> verbose, $VERBOSE = $VERBOSE, nil
>>
>> What the heck is that line doing??
>
> Haha... it's a Perl/Ruby idiom...
>
> x, y = y, x # swap values of x and y
>
> So he was just saving off $VERBOSE so he
> could restore it at the end.
>
Thank you!

I see the parentheses now:

(x, y) = (y, x)

I recall seeing that idiom and highlighting
it, too. But when I saw it in real life, the
commas messed me up. I saw it as:

(x), (y = y), (x)

I read your message that way, too, the first
6 times I looked at it.

It's interesting how natural language
processing swaps the precedence of = and ,
compared to the compiler.