[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

windows bat file help needed for rubygems

Eric Hodel

12/25/2006 11:25:00 PM

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 Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


4 Answers

Wilson Bilkovich

12/25/2006 11:40:00 PM

0

On 12/25/06, Eric Hodel <drbrain@segment7.net> wrote:
> 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.
>

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.

Eric Hodel

12/25/2006 11:57:00 PM

0

On Dec 25, 2006, at 15:39, Wilson Bilkovich wrote:
> On 12/25/06, Eric Hodel <drbrain@segment7.net> wrote:
>> 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
>
> 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 Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


Eric Hodel

12/26/2006 12:22:00 AM

0

On Dec 25, 2006, at 15:57, Eric Hodel wrote:
> On Dec 25, 2006, at 15:39, Wilson Bilkovich wrote:
>> On 12/25/06, Eric Hodel <drbrain@segment7.net> wrote:
>>> 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
>>
>> 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 Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


Wilson Bilkovich

12/26/2006 12:27:00 AM

0

On 12/25/06, Eric Hodel <drbrain@segment7.net> wrote:
> On Dec 25, 2006, at 15:57, Eric Hodel wrote:
> > On Dec 25, 2006, at 15:39, Wilson Bilkovich wrote:
> >> On 12/25/06, Eric Hodel <drbrain@segment7.net> wrote:
> >>> 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
> >>
> >> 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.
>

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.