Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b0609d

Browse files
[3.10] bpo-45382: test.pythoninfo logs more Windows versions (GH-30891) (GH-30894)
Add the following info to test.pythoninfo: * windows.ver: output of the shell "ver" command * windows.version and windows.version_caption: output of the "wmic os get Caption,Version /value" command. (cherry picked from commit b0898f4) * bpo-45382: test.pythoninfo: set wmic.exe encoding to OEM (GH-30890) (cherry picked from commit cef0a54) (cherry picked from commit 4a57fa2) Co-authored-by: Victor Stinner <[email protected]>
1 parent ad6ddd8 commit 0b0609d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Lib/test/pythoninfo.py

+42
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,48 @@ def collect_windows(info_add):
719719
except (ImportError, AttributeError):
720720
pass
721721

722+
import subprocess
723+
try:
724+
# When wmic.exe output is redirected to a pipe,
725+
# it uses the OEM code page
726+
proc = subprocess.Popen(["wmic", "os", "get", "Caption,Version", "/value"],
727+
stdout=subprocess.PIPE,
728+
stderr=subprocess.PIPE,
729+
encoding="oem",
730+
text=True)
731+
output, stderr = proc.communicate()
732+
if proc.returncode:
733+
output = ""
734+
except OSError:
735+
pass
736+
else:
737+
for line in output.splitlines():
738+
line = line.strip()
739+
if line.startswith('Caption='):
740+
line = line.removeprefix('Caption=').strip()
741+
if line:
742+
info_add('windows.version_caption', line)
743+
elif line.startswith('Version='):
744+
line = line.removeprefix('Version=').strip()
745+
if line:
746+
info_add('windows.version', line)
747+
748+
try:
749+
proc = subprocess.Popen(["ver"], shell=True,
750+
stdout=subprocess.PIPE,
751+
stderr=subprocess.PIPE,
752+
text=True)
753+
output = proc.communicate()[0]
754+
if proc.returncode:
755+
output = ""
756+
except OSError:
757+
return
758+
else:
759+
output = output.strip()
760+
line = output.splitlines()[0]
761+
if line:
762+
info_add('windows.ver', line)
763+
722764

723765
def collect_fips(info_add):
724766
try:

0 commit comments

Comments
 (0)