GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||
GeezerVison is showing github.com — bpo-45382: test.pythoninfo: set wmic.exe encoding to OEM by vstinner · Pull Request #30890 · python/cpython Conversation
|
| # 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", |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
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)
…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]>
… (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]>
…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]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.