Skip to content

Commit

Permalink
Fix check_output erroring due to incorrect encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
zer0k-z authored and dvander committed Feb 28, 2024
1 parent 2d4620d commit 63d8fd8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ambuild2/frontend/cpp/msvc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def run_batch(contents):
try:
fp.write(contents.encode('ascii'))
fp.close()
return subprocess.check_output([fp.name]).decode('utf-8')
return subprocess.check_output([fp.name]).decode(GetCodePage())
finally:
os.unlink(fp.name)

Expand Down Expand Up @@ -251,3 +251,11 @@ def DetectInclusionPattern(text):
return re.escape(phrase) + r'\s+([A-Za-z]:\\.*)$'

raise Exception('Could not find compiler inclusion pattern')

def GetCodePage():
stdout = subprocess.run(
"chcp", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
stdin=subprocess.DEVNULL
).stdout
return re.match(b".+: (\d+)\s*$", stdout).group(1).decode()

0 comments on commit 63d8fd8

Please sign in to comment.