windows bat file help needed for rubygems

E

Eric Hodel

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.
 
W

Wilson Bilkovich

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.
 
E

Eric Hodel

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.
 
E

Eric Hodel

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.
 
W

Wilson Bilkovich

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top