From: "rutsky (Vladimir Rutsky)" Date: 2013-03-14T20:26:34+09:00 Subject: [ruby-core:53406] [ruby-trunk - Feature #8083] Exit status is limited to one-byte values which is invalid for Windows Issue #8083 has been updated by rutsky (Vladimir Rutsky). =begin I cannot find exact definition of possible exit codes on Windows, but here is ExitProcess function declaration [1]: VOID WINAPI ExitProcess( _In_ UINT uExitCode ); UINT type definition [2]: An unsigned INT. The range is 0 through 4294967295 decimal. GetExitCodeProcess declaration [3] (looks like it used in CRuby to get exit status): BOOL WINAPI GetExitCodeProcess( _In_ HANDLE hProcess, _Out_ LPDWORD lpExitCode ); LPDWORD type definition [4]: typedef DWORD *LPDWORD; DWORD type definition [5]: A 32-bit unsigned integer. The range is 0 through 4294967295 decimal. Not sure about all Windows platforms, but at least on Windows 7 error codes in full 32-bit range can be retrieved in practice: C:\Python27>python.exe -c "import ctypes, ctypes.wintypes; ctypes.windll.kernel32.ExitProcess(ctypes.wintypes.UINT(30))" C:\Python27>echo %errorlevel% 30 C:\Python27>python.exe -c "import ctypes, ctypes.wintypes; ctypes.windll.kernel32.ExitProcess(ctypes.wintypes.UINT(2**31 - 1))" C:\Python27>echo %errorlevel% 2147483647 C:\Python27>python.exe -c "import ctypes, ctypes.wintypes; ctypes.windll.kernel32.ExitProcess(ctypes.wintypes.UINT(2**31))" C:\Python27>echo %errorlevel% -2147483648 C:\Python27>python.exe -c "import ctypes, ctypes.wintypes; ctypes.windll.kernel32.ExitProcess(ctypes.wintypes.UINT(2**32 - 1))" C:\Python27>echo %errorlevel% -1 [1] http://msdn.microsoft.com/en-us/library/windows/desktop/ms682658%28v=vs.85%29.aspx [2] http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx#UINT [3] http://msdn.microsoft.com/en-us/library/windows/desktop/ms683189%28v=vs.85%29.aspx [4] http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx#LPDWORD [5] http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx#DWORD =end ---------------------------------------- Feature #8083: Exit status is limited to one-byte values which is invalid for Windows https://bugs.ruby-lang.org/issues/8083#change-37597 Author: rutsky (Vladimir Rutsky) Status: Assigned Priority: Normal Assignee: cruby-windows Category: platform/windows Target version: =begin Windows uses 32-bit process exit codes so Ruby incorrectly truncates them to one byte: C:\Ruby193\bin>ruby -e "system('C:\windows\system32\cmd.exe /c exit 255'); puts $?.exitstatus" 255 C:\Ruby193\bin>ruby -e "system('C:\windows\system32\cmd.exe /c exit 256'); puts $?.exitstatus" 0 C:\Ruby193\bin>ruby -e "system('C:\windows\system32\cmd.exe /c exit 257'); puts $?.exitstatus" 1 Similar code works correctly in Python: C:\Python27>python -c "import subprocess; print subprocess.call('C:\windows\system32\cmd.exe /c exit 255')" 255 C:\Python27>python -c "import subprocess; print subprocess.call('C:\windows\system32\cmd.exe /c exit 256')" 256 C:\Python27>python -c "import subprocess; print subprocess.call('C:\windows\system32\cmd.exe /c exit 257')" 257 =end -- http://bugs.ruby-lang.org/