GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-45382: test.pythoninfo: set wmic.exe encoding to OEM by vstinner · Pull Request #30890 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Jan 25, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

https://bugs.python.org/issue45382

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
bpo-45382: test.pythoninfo: set wmic.exe encoding to OEM
27a39bd
@vstinner vstinner added the skip news label Jan 25, 2022
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Jan 25, 2022
@bedevere-bot bedevere-bot added the awaiting core review label Jan 25, 2022
@vstinner
vstinner merged commit cef0a54 into python:main Jan 25, 2022
@vstinner
vstinner deleted the wmic_oem branch January 25, 2022 19:02
@bedevere-bot bedevere-bot removed the awaiting core review label Jan 25, 2022
eryksun
eryksun reviewed Jan 25, 2022
View reviewed changes
Comment thread Lib/test/pythoninfo.py
Comment on lines +734 to +739
# When wmic.exe output is redirected to a pipe,
# it uses the OEM code page
proc = subprocess.Popen(["wmic", "os", "get", "Caption,Version", "/value"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="oem",

@eryksun eryksun Jan 25, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of Microsoft's tools support formatting output as XML or JSON, which can generally be parsed more reliably. For example:

import subprocess
import xml.etree.ElementTree as ET

p = subprocess.run('wmic.exe os get Caption,Version /format:rawxml', 
        capture_output=True, encoding='oem')
root = ET.fromstring(p.stdout)
caption = root.find('.//PROPERTY[@NAME="Caption"]/VALUE').text
version = root.find('.//PROPERTY[@NAME="Version"]/VALUE').text

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Jan 25, 2022

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please propose a PR if you prefer to parse XML than plain text. I don't want to invest too much time in this code, since I'm not using Windows :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Jan 25, 2022

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, maybe a more "correct" implementation is required if the function enters the stdlib platform module, but this PR is only about test.pythoninfo which is only used ... for tests ;-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
vstinner added a commit that referenced this pull request Jan 25, 2022
@vstinner
[3.10] bpo-45382: test.pythoninfo logs more Windows versions (GH-30891)
4a57fa2
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)
@miss-islington miss-islington mentioned this pull request Jan 25, 2022
[3.9] [3.10] bpo-45382: test.pythoninfo logs more Windows versions (GH-30891) #30894
Merged
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 25, 2022
@vstinner @miss-islington
[3.10] bpo-45382: test.pythoninfo logs more Windows versions (pythonG…
1d23fe2
…H-30891)

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 (pythonGH-30890)

(cherry picked from commit cef0a54)
(cherry picked from commit 4a57fa2)

Co-authored-by: Victor Stinner <[email protected]>
ambv pushed a commit that referenced this pull request Mar 16, 2022
@miss-islington @vstinner
[3.10] bpo-45382: test.pythoninfo logs more Windows versions (GH-30891)…
0b0609d
… (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]>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
@miss-islington @vstinner @hello-adam
[3.10] bpo-45382: test.pythoninfo logs more Windows versions (pythonG…
de91a5a
…H-30891) (pythonGH-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 (pythonGH-30890)

(cherry picked from commit cef0a54)
(cherry picked from commit 4a57fa2)

Co-authored-by: Victor Stinner <[email protected]>
@sahsariga111 sahsariga111 mannequin mentioned this pull request Aug 25, 2022
platform() is not able to detect windows 11 #89545
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@eryksun eryksun eryksun left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@vstinner @eryksun @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.