[3.10] bpo-45382: test.pythoninfo logs more Windows versions (GH-30891) · python/cpython@4a57fa2

GitHub

@@ -720,6 +720,48 @@ def collect_windows(info_add):

720720except (ImportError, AttributeError):

721721pass

722722723+importsubprocess

724+try:

725+# When wmic.exe output is redirected to a pipe,

726+# it uses the OEM code page

727+proc=subprocess.Popen(["wmic", "os", "get", "Caption,Version", "/value"],

728+stdout=subprocess.PIPE,

729+stderr=subprocess.PIPE,

730+encoding="oem",

731+text=True)

732+output, stderr=proc.communicate()

733+ifproc.returncode:

734+output=""

735+exceptOSError:

736+pass

737+else:

738+forlineinoutput.splitlines():

739+line=line.strip()

740+ifline.startswith('Caption='):

741+line=line.removeprefix('Caption=').strip()

742+ifline:

743+info_add('windows.version_caption', line)

744+elifline.startswith('Version='):

745+line=line.removeprefix('Version=').strip()

746+ifline:

747+info_add('windows.version', line)

748+749+try:

750+proc=subprocess.Popen(["ver"], shell=True,

751+stdout=subprocess.PIPE,

752+stderr=subprocess.PIPE,

753+text=True)

754+output=proc.communicate()[0]

755+ifproc.returncode:

756+output=""

757+exceptOSError:

758+return

759+else:

760+output=output.strip()

761+line=output.splitlines()[0]

762+ifline:

763+info_add('windows.ver', line)

764+723765724766defcollect_fips(info_add):

725767try: