# Rake bug on Windows

**URL:** <https://www.ruby-forum.com/t/rake-bug-on-windows/89814>\
**Category:** Ruby\
**Created:** [March 22, 2007, 10:42pm UTC](https://www.ruby-forum.com/t/rake-bug-on-windows/89814 "2007-03-22T22:42:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [March 22, 2007, 10:42pm UTC](https://www.ruby-forum.com/t/rake-bug-on-windows/89814/1 "2007-03-22T22:42:42Z")

</div>

I can’t find out where to file this:

Rake returns 0 exit status on Windows, even after failure.

> rake -V  
> c:0:Warning: require\_gem is obsolete. Use gem instead.  
> rake, version 0.7.2

> ruby -v  
> ruby 1.8.5 (2006-08-25) [i386-mswin32]

> true && echo “Success!”  
> “Success!”

> false && echo “Success!”

> rake notthere && echo “Success!”  
> c:0:Warning: require\_gem is obsolete. Use gem instead.  
> (in C:/medwiz/delanor/development)  
> rake aborted!  
> Don’t know how to build task ‘notthere’

(See full trace by running task with --trace)  
“Success!”

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [March 22, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/rake-bug-on-windows/89814/2 "2007-03-22T23:51:25Z")

</div>

On Mar 22, 3:38 pm, “S. Robert J.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Rake returns 0 exit status on Windows, even after failure.

Not really. It appears that the problem is with the rake.bat batch  
file that is used on Windows. Pared down, it looks something like  
this:

“%~d0%~p0ruby” -x “%~f0” %\*  
goto endofruby  
#!/bin/ruby

require ‘rubygems’  
require ‘rake’  
load ‘rake’

**END**  
:endofruby

The problem is that the batch file doesn’t seem to properly pass along  
the exit code in a way that causes Windows to do the right thing if  
you perform a goto in the batch file. Here’s a simple test case:

C:\>type tmp1.bat  
@echo off  
ruby -e “puts ‘failing…’; exit(1)”

C:\>tmp1.bat && echo “success”  
failing…

C:\>type tmp2.bat  
@echo off  
ruby -e “puts ‘failing…’; exit(1)”  
goto alldone  
:alldone  
echo The error level is %ERRORLEVEL%

C:\>tmp2.bat && echo “success”  
failing…  
The error level is 1  
“success”

I hoped maybe I could fix this by really truly having the batch file  
return the right error code, but no such luck:  
C:\>exit /?  
Quits the CMD.EXE program (command interpreter) or the current  
batch script.

```
EXIT [/B] [exitCode]

/B specifies to exit the current batch script instead of
          CMD.EXE. If executed from outside a batch script, it
          will quit CMD.EXE

exitCode specifies a numeric number. if /B is specified, sets
          ERRORLEVEL that number. If quitting CMD.EXE, sets the

```

process  
exit code with that number.

C:\>type tmp3.bat  
@echo off  
ruby -e “puts ‘failing…’; exit(1)”  
goto alldone  
:alldone  
echo The error level is %ERRORLEVEL%  
EXIT /B %ERRORLEVEL%

C:\>tmp3.bat && echo “success”  
failing…  
The error level is 1  
“success”

If this is important, you could modify the rake.bat file on Windows  
(in c:\ruby\bin) to have it not use the trick ruby -x option, and  
instead just use -e instead. Something like:

C:\>type \ruby\bin\rake.bat  
@“%~d0%~p0ruby” -e “require ‘rubygems’; require ‘rake’; load ‘rake’”  
%\*

C:\>rake && echo “success”  
rake aborted!  
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,  
Rakefile.rb)  
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:1849:in  
`load\_rakefile’  
(See full trace by running task with --trace)

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [March 23, 2007, 6:18am UTC](https://www.ruby-forum.com/t/rake-bug-on-windows/89814/3 "2007-03-23T06:18:53Z")

</div>

On 3/22/07, Phrogz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Not really. It appears that the problem is with the rake.bat batch  
> file that is used on Windows.

Yes. This is the reason why invoking Rake in CruiseControl.rb looks so  
damn  
convoluted:

```
%{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"}
