# Ruby Gem Creates Broken Batch File for Rake

**URL:** <https://www.ruby-forum.com/t/ruby-gem-creates-broken-batch-file-for-rake/91594>\
**Category:** Ruby\
**Created:** [April 10, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/ruby-gem-creates-broken-batch-file-for-rake/91594 "2007-04-10T19:36:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![runxc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ec8ea/32.png) [@runxc](https://www.ruby-forum.com/u/runxc)\
**Post date:** [April 10, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/ruby-gem-creates-broken-batch-file-for-rake/91594/1 "2007-04-10T19:36:46Z")

</div>

Recently I have been integrating Rake with Nant. Specifically, I have  
been creating Nant tasks that trigger Rake. In the process of doing  
this, I have run into a problem: namely when Rake fails, Nant thinks  
that it succeeds. I have tracked down the problem to the Rake batch  
file, apparently created by the Gem system, that is used to invoke  
Rake.

The problem is that the return code (which is 1, failure) returned  
from the  
Ruby process is not propagated by the Rake batch file. Nant thus sees  
a return code of 0 (success). I have worked around this problem by not  
using the Rake batch file and invoking ruby.exe directly. However, it  
seems to me that others may also run into this problem, and also that  
the Gem batch file generation system could be fixed. I suspect this  
problem could also affect other gems besides Rake.

Here is my original Nant task, which did not correctly report Rake  
failures:

Here is my corrected Nant task:

Here is some information from [CC.Net](http://CC.Net) (which I am also using) that I  
used to help debug return codes (aka error levels) on Windows:

[http://confluence.public.thoughtworks.org/display/CCNET/FAQ](http://confluence.public.thoughtworks.org/display/CCNET/FAQ)  
See “[CruiseControl.NET](http://CruiseControl.NET) is reporting that the build succeeded when it  
failed. Why?”

A collegue suggested that I directly modify the batch file, but since  
it seems to be autogenerated by Rake, and it doesn’t seem to actually  
be doing very much (I turned “@echo on” to see what it was doing), I  
figured it would be easier to simply avoid using it.

I would appreciate comments and alternate suggestions.

Bret

Bret P., [www.pettichord.com](http://www.pettichord.com)  
Lead Developer, Watir, [http://wtr.rubyforge.org](http://wtr.rubyforge.org)  
Test Architect, Dovetail, [www.dovetailsoftware.com](http://www.dovetailsoftware.com)

---

<div class="post-metadata">

**Author:** ![runxc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ec8ea/32.png) [@runxc](https://www.ruby-forum.com/u/runxc)\
**Post date:** [April 10, 2007, 8:36pm UTC](https://www.ruby-forum.com/t/ruby-gem-creates-broken-batch-file-for-rake/91594/2 "2007-04-10T20:36:57Z")

</div>

On 4/10/07, Bret P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> figured it would be easier to simply avoid using it.

We figured out as much in the course of CruiseControl.rb project.  
Have a look at Build#rake() method in app/models/build.rb of that code  
base.

---

<div class="post-metadata">

**Author:** ![runxc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ec8ea/32.png) [@runxc](https://www.ruby-forum.com/u/runxc)\
**Post date:** [April 10, 2007, 9:36pm UTC](https://www.ruby-forum.com/t/ruby-gem-creates-broken-batch-file-for-rake/91594/3 "2007-04-10T21:36:09Z")

</div>

On 4/10/07, Alexey V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> We figured out as much in the course of CruiseControl.rb project.  
> Have a look at Build#rake() method in app/models/build.rb of that code  
> base.

For the rest of you, here is what they did:

def rake  
# --nosearch flag here prevents CC.rb from building itself when a  
project has no Rakefile  
%{ruby -e “require ‘rubygems’ rescue nil; require ‘rake’; load ‘#{  
File.expand\_path(RAILS\_ROOT)}/tasks/cc\_build.rake’; ARGV \<\<  
‘–nosearch’#{CruiseControl::Log.verbose? ? " \<\< ‘–trace’” : “”} \<\<  
‘cc:build’; Rake.application.run"}  
end

Thanks for the comment.

Bret

---

<div class="post-metadata">

**Author:** ![runxc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ec8ea/32.png) [@runxc](https://www.ruby-forum.com/u/runxc)\
**Post date:** [April 10, 2007, 9:42pm UTC](https://www.ruby-forum.com/t/ruby-gem-creates-broken-batch-file-for-rake/91594/4 "2007-04-10T21:42:09Z")

</div>

On 4/10/07, Bret P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> def rake  
> # --nosearch flag here prevents CC.rb from building itself when a  
> project has no Rakefile  
> %{ruby -e “require ‘rubygems’ rescue nil; require ‘rake’; load ‘#{  
> File.expand\_path(RAILS\_ROOT)}/tasks/cc\_build.rake’; ARGV \<\<  
> ‘–nosearch’#{CruiseControl::Log.verbose? ? " \<\< ‘–trace’” : “”} \<\<  
> ‘cc:build’; Rake.application.run"}  
> end

Ugly, isn’t it? 🙂

Alex
