Skip to content

Fix Windows az launcher mangling non-ASCII output under isolated mode - #33935

Open
hasu (jun2077681) wants to merge 2 commits into
Azure:devfrom
jun2077681:fix/az-cmd-utf8-isolated-mode
Open

Fix Windows az launcher mangling non-ASCII output under isolated mode#33935
hasu (jun2077681) wants to merge 2 commits into
Azure:devfrom
jun2077681:fix/az-cmd-utf8-isolated-mode

Conversation

@jun2077681

@jun2077681 hasu (jun2077681) commented Aug 20, 2026

Copy link
Copy Markdown

🤖 PR Validation — ️✔️ All clear

Breaking Changes Tests
️✔️ None ️✔️ 130/130

Summary

  • az_msi.cmd / az_zip.cmd invoke the bundled Python with -I (isolated mode), which drops -E behavior and ignores PYTHONUTF8/PYTHONIOENCODING.
  • On Windows, when the legacy ANSI codepage isn't UTF-8 (e.g. Korean/Chinese locales), this causes non-ASCII CLI output to come out as mojibake or get silently discarded (Unable to encode the output with cp949/cp1252 encoding. Unsupported characters are discarded.).
  • -X utf8 (PEP 540) is an independent interpreter flag from -I — it only forces UTF-8 mode for stdio, and does not restore any of -I's ignored env vars or site-packages behavior. Adding it keeps the isolation guarantees intact while fixing output encoding.

Change

Two one-line edits:

-  "%~dp0\..\python.exe" -IBm azure.cli %*
+  "%~dp0\..\python.exe" -X utf8 -IBm azure.cli %*

in both build_scripts/windows/scripts/az_msi.cmd and az_zip.cmd.

Verification

Reproduced locally against an installed 2.89.1 MSI build (C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin\az.cmd):

  • Before: az repos pr show --id <id> --query title -o tsv on a PR with a Korean title printed mojibake (?? ??-style output).
  • After patching the launcher with -X utf8, the same command prints the title correctly.
  • Confirmed isolation is unaffected: setting a bogus PYTHONPATH before/after the patch has no effect on CLI behavior in either case (env var still ignored).

Fixes #28497

python -I isolated mode ignores PYTHONUTF8/PYTHONIOENCODING, so
non-ASCII output (e.g. Korean, Chinese) gets mangled on Windows when
the console's ANSI codepage isn't UTF-8. Adding -X utf8 forces PEP 540
UTF-8 mode for stdio without weakening isolation (-I still ignores
PYTHONPATH, site-packages, and script-dir sys.path insertion).

Fixes Azure#28497
Copilot AI lite review requested due to automatic review settings August 20, 2026 01:02
@azure-client-tools-bot-prd

Copy link
Copy Markdown

Hi hasu (@jun2077681),
Since the current milestone time is less than 7 days, this pr may not catch up with this release.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@jun2077681

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses Windows console encoding corruption for non-ASCII Azure CLI output when the MSI/ZIP launchers run the bundled Python in isolated mode (-I). It does so by explicitly enabling UTF-8 mode via the interpreter flag -X utf8, which preserves isolation while fixing stdout/stderr encoding behavior on non-UTF-8 legacy codepages.

Changes:

  • Add -X utf8 to the ZIP launcher (az_zip.cmd) when invoking python.exe -IBm azure.cli.
  • Add -X utf8 to the MSI launcher (az_msi.cmd) when invoking python.exe -IBm azure.cli.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
build_scripts/windows/scripts/az_zip.cmd Adds -X utf8 to force UTF-8 stdio in the ZIP launcher while keeping isolated mode.
build_scripts/windows/scripts/az_msi.cmd Adds -X utf8 to force UTF-8 stdio in the MSI launcher while keeping isolated mode.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@IF EXIST "%~dp0\..\python.exe" (
SET AZ_INSTALLER=MSI
"%~dp0\..\python.exe" -IBm azure.cli %*
"%~dp0\..\python.exe" -X utf8 -IBm azure.cli %*

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch — added the same -X utf8 flag to az and azps.ps1 as well (they hit the identical -IBm isolated-mode encoding issue).

Both invoke the bundled python.exe with -IBm as well, so they hit the
same non-ASCII output corruption as the .cmd launchers.
@yonzhan

Copy link
Copy Markdown
Collaborator

Windows az launcher

@coopercox-ms Cooper Cox (coopercox-ms) added the Azure Client Tools Agent Requested Request Azure Client Tools Agent testing and review label Aug 20, 2026
@azure-client-tools-agent

Copy link
Copy Markdown
Contributor

Live test skipped

⏭️ Skipping the live test for this revision because no new test file was added (tests/**/test_*.py).

The live-test pipeline runs only the test files a PR changes, so there is nothing to execute for this commit. This is informational — a regression test is encouraged where it makes sense, but not required. If a test file is added in a later commit, the live test will run automatically.

@azure-client-tools-agent azure-client-tools-agent Bot added the azure-client-tools-agent Pull request reviewed by Azure Client Tools Agent label Aug 20, 2026

@azure-client-tools-agent azure-client-tools-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Validation Summary

Current head commit (5ebb85e):

CI (GitHub Actions): ✅ 1/1 checks passed.

Live test: skipped — this PR does not change any test files (tests/**/test_*.py).

No failures found. This PR looks ready for a maintainer to merge.

@azure-client-tools-agent azure-client-tools-agent Bot removed the Azure Client Tools Agent Requested Request Azure Client Tools Agent testing and review label Aug 20, 2026
@coopercox-ms

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure-client-tools-agent Pull request reviewed by Azure Client Tools Agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider use UTF-8 by default for Azure CLI

5 participants