{Packaging} Fix azps.ps1 wrapper to propagate exit codes and forward stdin#33260
{Packaging} Fix azps.ps1 wrapper to propagate exit codes and forward stdin#33260AaronRobinsonMSFT wants to merge 2 commits intoAzure:devfrom
Conversation
…stdin The azps.ps1 wrapper scripts (both the MSI and pip variants) had two minor issues: 1. Exit codes from the underlying python.exe invocation were not propagated, so callers (especially pwsh.exe -Command) would see a successful exit even when the CLI failed. 2. Stdin piped into the wrapper was not forwarded to the Python process, so commands that read from stdin did not receive input. Pipe $input into the child process and add an explicit `exit $LASTEXITCODE` at the end of both wrappers. Add regression tests to test_msi_installation.ps1 to cover both behaviors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Validation for Azure CLI Full Test Starting...
Thanks for your contribution! |
|
Hi @AaronRobinsonMSFT, |
|
Validation for Breaking Change Starting...
Thanks for your contribution! |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull request overview
This PR updates the Windows PowerShell azps.ps1 wrappers (MSI + pip) to better behave like a thin launcher for python.exe -m azure.cli, aiming to propagate the child process exit code and forward stdin for piped scenarios. It also adds MSI installation regression coverage for wrapper exit-code propagation.
Changes:
- Pipe
$inputinto the childpython.exeinvocation in bothazps.ps1wrappers and explicitlyexit $LASTEXITCODE. - Add MSI installation regression tests validating
azps.ps1success and non-zero exit codes (direct +pwsh.exe -Command).
Show a summary per file
| File | Description |
|---|---|
src/azure-cli/azps.ps1 |
Updates pip-installed wrapper to forward stdin and re-emit exit code. |
build_scripts/windows/scripts/azps.ps1 |
Updates MSI wrapper to forward stdin and re-emit exit code. |
build_scripts/windows/scripts/test_msi_installation.ps1 |
Adds MSI regression assertions for wrapper exit-code behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 4
- Only pipe $input into python.exe when the wrapper is actually receiving pipeline input ($MyInvocation.ExpectingInput). Otherwise invoke python.exe directly so interactive stdin is inherited from the console instead of being closed at EOF. - Fix pre-existing 'Perfer' typo in src/azure-cli/azps.ps1. - Harden the pwsh.exe -Command regression test: skip if pwsh.exe is unavailable, reset $global:LASTEXITCODE before the call, and also check $? so a command-not-found doesn't false-pass via a stale non-zero $LASTEXITCODE. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Thanks for the contribution. There are actually more issues with As previously discussed with PowerShell team, there is no plan to improve the |
Related command
azps.ps1(Windows PowerShell wrapper installed by the MSI and available in the pip package)Description
The
azps.ps1wrapper scripts had two minor issues previously discussed:python.exe -m azure.cliwith&but never re-emitted$LASTEXITCODE. When the wrapper is invoked throughpwsh.exe -Command(a very common pattern in CI), PowerShell only surfaces the script's exit code if the script itself callsexit N. As a result, failed CLI invocations appeared to succeed.azps.ps1was not passed through to the Python process, so any command that reads from stdin received nothing.Fix
$inputinto the childpython.exeinvocation in both wrappers (build_scripts/windows/scripts/azps.ps1for the MSI build, andsrc/azure-cli/azps.ps1for pip).exit $LASTEXITCODEat the end so the exit code surfaces correctly even underpwsh.exe -Command.build_scripts/windows/scripts/test_msi_installation.ps1covering both the direct-invocation andpwsh.exe -Commandpaths.Testing
New assertions in
test_msi_installation.ps1exercise:azps.ps1 --versionsucceeds.azps.ps1 <bad-command>returns a non-zero exit code (direct invocation).pwsh.exe -NoProfile -Command "& azps.ps1 <bad-command>; exit $LASTEXITCODE"returns a non-zero exit code.