Skip to content

Try to avoid invoking a new process to determine the Windows version in the platform module #129294

Description

@tomergert

Feature or enhancement

Proposal:

In Lib/platform.py, there's a code aimed to determine the Windows version python runs in.

forcmdin ('ver', 'command /c ver', 'cmd /c ver'):
try:
info=subprocess.check_output(cmd,
stdin=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
text=True,
encoding="locale",
shell=True)

As much as I understand, one shouldn't invoke whole new process just to question what OS version he runs at.

so just before invoking cmd.exe, we will try to question winapi directly.

# Load ntdll.dll and call RtlGetVersionntdll=ctypes.WinDLL("ntdll")
rtl_get_version=ntdll.RtlGetVersionrtl_get_version(ctypes.byref(os_version))

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions