Project

General

Profile

Actions

Feature #8083

open

Exit status is limited to one-byte values which is invalid for Windows

Added by rutsky (Vladimir Rutsky) about 11 years ago. Updated about 11 years ago.

Status:
Assigned
Assignee:
Target version:
-
[ruby-core:53368]

Description

=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

Updated by luislavena (Luis Lavena) about 11 years ago

  • Status changed from Open to Feedback

Can you provide links to MSDN article that states this? (32-bits exit codes)

Thank you.

Updated by phasis68 (Heesob Park) about 11 years ago

According to the document http://en.wikipedia.org/wiki/Exit_status#Windows,
"Windows uses 32-bit signed integers as exit codes. If a process fails initialization, a Windows system error code may be returned. Windows system error codes are available online.
Exit codes are directly referenced, for example, by the command line interpreter CMD.exe in the errorlevel terminology inherited from DOS. .NET Framework processes and the Windows PowerShell refer to it as the ExitCode property of the Process object."

Refer to
http://stackoverflow.com/questions/179565/exitcodes-bigger-than-255-possible
http://www.hiteksoftware.com/mize/Knowledge/articles/049.htm

Actions #3

Updated by usa (Usaku NAKAMURA) about 11 years ago

  • Tracker changed from Bug to Feature
  • Status changed from Feedback to Assigned

This may be not a bug but a feature.

Updated by rutsky (Vladimir Rutsky) about 11 years ago

=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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0