Repository navigation
Conversation
…cmd /C
`rtk err`, `rtk test` and `rtk summary` take a command as one string and
run it through a shell. On Windows that shell was hardcoded to `cmd /C`,
in two separate copies of the same helper, so every PowerShell cmdlet and
pipeline handed to them failed:
rtk summary "Get-ChildItem | Measure-Object"
'Get-ChildItem' is not recognized as an internal or external command
Consolidate both copies into `core::shell` and resolve the shell instead:
1. `RTK_SHELL` wins when set (`cmd`, `powershell`, `pwsh`, `sh`, `bash`,
or any executable name or path).
2. On Windows, if the command's leading word is neither a `cmd` builtin
nor a program on PATH, it is PowerShell syntax -- route it to `pwsh`
if installed, else `powershell`.
3. Otherwise the platform default: `cmd` on Windows, `sh` elsewhere.
Non-Windows behaviour is unchanged: without `RTK_SHELL` it is still
`sh -c`, same as before.
Step 2 is deliberately not "detect the parent shell". That needs Win32
calls the crate forbids (`unsafe_code = "deny"`), and the environment
carries no usable signal -- `PSModulePath` is inherited by `cmd`
children, so it proves nothing. Reading the command text costs one PATH
lookup and is not locale-dependent the way parsing cmd.exe's error
message would be.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Collaborator
|
Thanks for working on this, rhishi99. #4125 (merged 2026-09-26) replaced the shell handling in rtk err, test and summary: positional commands now run directly, and a script goes through an explicit --shell, which accepts pwsh and powershell with -Command from a shared src/core/shell.rs. The duplicated cmd /C helpers this PR merges into one are already gone on develop. What develop still lacks is a way to reach PowerShell without --shell, such as an RTK_SHELL default or detection of PowerShell syntax; if you still want that, an issue or a narrow PR on the --shell model would be welcome. If I missed something this PR covers, please comment or reopen. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
rtk err,rtk testandrtk summarytake a command as one string and run it through a shell. On Windows that shell was hardcoded tocmd /C— in two separate copies of the same helper (cmds/rust/runner.rs,cmds/system/summary.rs). Every PowerShell cmdlet or pipeline handed to them fails:PowerShell is the default shell on Windows, so this is the common case, not an edge case.
Fix
Both copies collapse into one
core::shellmodule which resolves the shell rather than assuming it:RTK_SHELLwins when set —cmd,powershell,pwsh,sh,bash, or any executable name or path.cmdbuiltin nor a program onPATH, it is PowerShell syntax → route topwshif installed, elsepowershell.cmdon Windows,shelsewhere.Non-Windows behaviour is unchanged — without
RTK_SHELLit is stillsh -c, exactly as before.Why not detect the parent shell
That is the obvious approach and it does not work here:
unsafe_code = "deny").PSModulePathis inherited bycmdchildren, so its presence proves nothing.is not recognized as an internal or external commandis locale-dependent.Deciding from the command text needs no parent process, costs one PATH lookup, and is locale-independent.
cmdbuiltins are listed explicitly because no file on PATH backs them, so a PATH lookup alone would misreaddirorechoas PowerShell.Testing
Unit tests in
core::shellcoverRTK_SHELLprecedence, builtin detection, PATH-program detection, the PowerShell fallback, quoted leading words, and the empty-command case. Docs added todocs/guide/getting-started/configuration.md.Full suite on
x86_64-pc-windows-gnu: 2626 passed.cargo fmt --checkandcargo clippy --all-targetsclean. The single unrelated failure on this toolchain is fixed in #3615.🤖 Generated with Claude Code