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

L

Luc Vantroys

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
 
M

Matt Todd

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.
 
S

Suraj N. Kurapati

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

Matt said:
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-----
 
E

Eric Armstrong

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?
 
N

nobu

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?.
 
E

Eric Armstrong

Eric said:
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
 
E

Eric Armstrong

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

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

adventurous! {system(cmd)}
What the heck is that line doing??
 
H

Hal Fulton

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


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
 
E

Eric Armstrong

Hal said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top