From 6792f6996b6757a89ab1245cb1fde6c8ab9a92ec Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Sun, 15 Dec 2024 12:28:31 +0100 Subject: [PATCH] Fix windows codepage detection using language pack When running `chcp` on a german Windows installation, the output contains a `.` after the code page: ``` > chcp Aktive Codepage: 850. ``` Allow an optional dot in the output parsing. --- ambuild2/frontend/cpp/msvc_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ambuild2/frontend/cpp/msvc_utils.py b/ambuild2/frontend/cpp/msvc_utils.py index b28a568..e9a3ee5 100644 --- a/ambuild2/frontend/cpp/msvc_utils.py +++ b/ambuild2/frontend/cpp/msvc_utils.py @@ -260,7 +260,10 @@ def GetCodePage(): stdout = subprocess.PIPE, stderr = subprocess.DEVNULL, stdin = subprocess.DEVNULL).stdout - codec = 'cp' + re.match(b".+: (\d+)\s*$", stdout).group(1).decode() + code_page = re.match(br".+: (\d+)\.?\s*$", stdout) + if code_page is None: + raise LookupError("Could not determine code page") + codec = 'cp' + code_page.group(1).decode() codecs.lookup(codec) return codec except LookupError: