# Windows bat file help needed for rubygems

**URL:** <https://www.ruby-forum.com/t/windows-bat-file-help-needed-for-rubygems/80401>\
**Category:** Ruby\
**Created:** [December 26, 2006, 12:26am UTC](https://www.ruby-forum.com/t/windows-bat-file-help-needed-for-rubygems/80401 "2006-12-26T00:26:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [December 26, 2006, 12:26am UTC](https://www.ruby-forum.com/t/windows-bat-file-help-needed-for-rubygems/80401/1 "2006-12-26T00:26:45Z")

</div>

How do I get a windows .bat file to return a proper exit code?

RubyGems build stubs that look something like this:

“c:\ruby\bin\ruby” -x “%~f0” %\*  
goto endofruby  
#!/bin/ruby  
abort ‘boom’  
**END**  
:endofruby

But if I run this:

ruby -e “system ‘stub.bat’; p $?”

I get the wrong exit code (0 instead of 1).

If I can get the right exit code then failure to build rake  
extensions will fail installs properly in Rubygems.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)

I LIT YOUR GEM ON FIRE!

---

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [December 26, 2006, 12:40am UTC](https://www.ruby-forum.com/t/windows-bat-file-help-needed-for-rubygems/80401/2 "2006-12-26T00:40:47Z")

</div>

On 12/25/06, Eric H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> But if I run this:
> 
> ruby -e “system ‘stub.bat’; p $?”
> 
> I get the wrong exit code (0 instead of 1).
> 
> If I can get the right exit code then failure to build rake  
> extensions will fail installs properly in Rubygems.

What do you get when you put:  
exit %ERRORLEVEL%  
under the :endofruby label?

From my quick test, the ruby interpreter returns a proper code, and  
the command shell sets the ERRORLEVEL variable correctly.

---

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [December 26, 2006, 12:58am UTC](https://www.ruby-forum.com/t/windows-bat-file-help-needed-for-rubygems/80401/3 "2006-12-26T00:58:48Z")

</div>

On Dec 25, 2006, at 15:39, Wilson B. wrote:

> > :endofruby
> 
> What do you get when you put:  
> exit %ERRORLEVEL%  
> under the :endofruby label?
> 
> From my quick test, the ruby interpreter returns a proper code, and  
> the command shell sets the ERRORLEVEL variable correctly.

Your name will live forever in the rubygems ChangeLog.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)

I LIT YOUR GEM ON FIRE!

---

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [December 26, 2006, 1:22am UTC](https://www.ruby-forum.com/t/windows-bat-file-help-needed-for-rubygems/80401/4 "2006-12-26T01:22:54Z")

</div>

On Dec 25, 2006, at 15:57, Eric H. wrote:

> > > **END**  
> > > :endofruby
> > 
> > What do you get when you put:  
> > exit %ERRORLEVEL%  
> > under the :endofruby label?
> > 
> > From my quick test, the ruby interpreter returns a proper code, and  
> > the command shell sets the ERRORLEVEL variable correctly.
> 
> Your name will live forever in the rubygems ChangeLog.

Hrm, it seems that gems doesn’t generate .bat files, but instead  
generates .cmd files. I’ll ask Curt about this.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)

I LIT YOUR GEM ON FIRE!

---

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [December 26, 2006, 1:26am UTC](https://www.ruby-forum.com/t/windows-bat-file-help-needed-for-rubygems/80401/5 "2006-12-26T01:26:54Z")

</div>

On 12/25/06, Eric H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > > abort ‘boom’  
> > > > Your name will live forever in the rubygems ChangeLog.
> 
> Hrm, it seems that gems doesn’t generate .bat files, but instead  
> generates .cmd files. I’ll ask Curt about this.

Should work the same in either. Since going with .cmd files discards  
Windows 98 compatibility (rightly), there are some other tricks that  
can be safely invoked. As a .CMD, ‘EXIT’ can take a /B argument that  
will exit from the script, but not the command shell as a whole.
