This is normal, and doesn't have much to do with Ruby. You get the
same result in a plain command prompt. When running a batch script
from Ruby (or any other program), a new cmd.exe instance must be
spawned to launch the batch file:
C:\>type a.bat @echo off
exit /B 29
C:\>cmd /c a.bat
C:\>echo %errorlevel%
0
When you run the batch file directly, you are not setting the exit
code, but simply the "errorlevel" of the current cmd instance. There
is no process exiting when running a.bat from the command line, so
there is no exit code to set by doing "exit /B 29".
Ruby gives you the exit code of the "process" - which is "cmd.exe",
and you are not asking "cmd.exe" to exit with any code other than 0.
You can change your .bat:
C:\>type b.bat @echo off
exit 29
C:\>cmd /c b.bat
C:\>echo %errorlevel%
29
But this .bat will exit your console window if run from the command
line. This may help though:
···
On Wed, Dec 16, 2009 at 8:18 AM, Wi siong Ko <weishng@hotmail.com> wrote:
Hi,
I would like to obtain the exit code from a child program. But all the
methods I tried were in vain. Here are two files that i used to test.
When testing if there is a bug, please try latest patchlevels.
Since you're using mswin32 installation and a really old patchlevel
(zero). Will recommend migrate to RubyInstaller:
Which is the successor of One-Click Installer and provides, at this
time under RC1, binaries for both 1.8.6 and 1.9.1-p243
···
On Dec 16, 5:32 am, Wi siong Ko <weis...@hotmail.com> wrote:
Luis Lavena wrote:
> On Dec 16, 4:18 am, Wi siong Ko <weis...@hotmail.com> wrote:
>> system('a.bat')
>> Can anyone help me?
> When reporting any issue, please include full version of Ruby (ruby -
> v) that you're using.