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

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-forum.com/.

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.

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

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?

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

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

Eric Armstrong wrote:

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

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

···

nobu@ruby-lang.org wrote:

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.