Forum: Ruby windows bat file help needed for rubygems

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-12-26 00:26
(Received via mailing list)
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.segment7.net

I LIT YOUR GEM ON FIRE!
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-12-26 00:40
(Received via mailing list)
On 12/25/06, Eric Hodel <drbrain@segment7.net> 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.
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-12-26 00:58
(Received via mailing list)
On Dec 25, 2006, at 15:39, Wilson Bilkovich 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 Hodel - drbrain@segment7.net - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-12-26 01:22
(Received via mailing list)
On Dec 25, 2006, at 15:57, Eric Hodel 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 Hodel - drbrain@segment7.net - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-12-26 01:26
(Received via mailing list)
On 12/25/06, Eric Hodel <drbrain@segment7.net> 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.
This topic is locked and can not be replied to.