Repository navigation
Description
rtk run -c '<script>' (and --shell cmd '<script>') hands the script to cmd.exe as an ordinary argument, so a script that carries its own quotes loses them to cmd's command-string parsing. A script whose program is a quoted path with spaces never starts.
Reported and reproduced on native Windows by @ryanduguid and independently confirmed by @bharvey42 on a different toolchain, while reviewing #4125. Filing so the evidence and the fix are not lost in that PR's thread — it is not a regression from #4125 and should not hold it.
Symptom
rtk run -c '"C:\path with spaces\rtk.exe" --version'
The child never starts; cmd reports the quoted path as an unknown command ('C:\path' is not recognized). The same command line handed straight to cmd /d /s /c with its outer command quoting works.
@bharvey42, with a node child that writes the argv it receives:
node argv.js "a b" c through run -c / err|test|summary --shell cmd
expected ["a b","c"]
actual ["\"a","b\"","c"]
Mechanism
src/core/shell.rs builds the explicit-shell command as resolved_command(program).arg(command_flag(program)).child_arg(script).
cmd.exe does not parse its command string by CommandLineToArgvW rules; it strips the first and last quote of the tail and performs no backslash processing. So neither std's escaping nor ChildArgExt's MSYS/libuv encoding is the right encoding for the /C payload — the script needs cmd's own quoting, which is /S plus one extra outer quote pair passed through raw_arg.
This is the same family as #3185 (quoting lost on re-execution, stray files from a > inside a quoted argument), #3691 (quoted cmd.exe commands not transparent) and #4102 (MSYS children and child_args coverage), but a distinct site: those are about argv handed to a child, this is about the command string handed to cmd.
Not a regression, with one caveat
The pre-#4125 code did Command::new("cmd").arg("/C").arg(&raw) — plain std escaping, also without /S — so the quoted-path case fails on stable too. @bharvey42's before-state on v0.50.0 (which already carries #3728) confirms it:
| Command through all four runners | v0.50.0 |
|---|---|
'a b' c |
["a","b","c"] |
"x > stray" |
["x"], plus an empty file stray |
sh -c 'exit 7' |
rc 0 |
nosuchcmd123 |
rc 1 |
"C:/Program Files/Git/cmd/git.exe" --version |
'C:/Program' is not recognized |
The caveat worth acting on: for a script with embedded quotes the two are differently wrong, and arguably worse now — stable dropped the quotes (["a","b","c"]), the current code injects backslashes (["\"a","b\"","c"]). The argument boundary is lost either way, but the text is now corrupted rather than only unquoted.
Fix
@ryanduguid has a patch and tests, verified on native Windows (Rust 1.91.0 MSVC): pass /S /C and the script in one extra pair of outer quotes through CommandExt::raw_arg, leaving direct argv and other shells on their existing encoding. @bharvey42 confirmed both halves matter — raw_arg alone fixes embedded quotes but a script starting with a quoted path still breaks, because cmd strips the first and last quote.
Their tests cover paths with spaces, & and parentheses, embedded quotes, trailing backslashes, redirection and exit code 7 across run, err, test and summary, including default cmd and upper-case CMD.EXE. The patch is in #4125 — worth lifting from there rather than rewriting.
Also reported to reproduce at #3505 and #4206.
Not verified
Linux and macOS are unaffected (the /C branch is Windows-only), but the patch has not been through upstream CI. Whoever picks this up should let the Windows job run it.
Activity
rtk-wshm-sync-bot commentedon Sep 26, 2026
🔍 Automated Triage
bughighSummary
On Windows,
rtk run -c/--shell cmdpass a script to cmd.exe with the wrong quoting, so quoted program paths never launch and embedded quotes get corrupted; fix (with tests) already exists in PR #4125.📁 Relevant files
src/core/shell.rsSuggested Actions
/S /C+ outer-quote fix for cmd.exe from PR fix(cli)!: preserve argv boundaries in generic runners #4125 rather than rewriting&/parens, redirection, exit code 7)Triaged automatically by wshm · This is an automated analysis, not a human review.
TechWizard9999 commentedon Sep 27, 2026
Hi @KuSh , Can I work on this
Could you please assign this ?
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
TechWizard9999 commentedon Oct 6, 2026
Hi @KuSh , As I dont have windows to test could you please take care of this issue
Thanks!!
bharvey42 commentedon Oct 8, 2026
I can take this, since I'm on Windows (Git Bash,
x86_64-pc-windows-gnu). The bug site hasn't changed on develop:src/core/shell.rs:174still does.arg(command_flag(program)).child_arg(script).My plan is to lift @ryanduguid's
/S /C+raw_argpatch and tests from #4125, credit them as co-author, and rerun the argv probe from the issue body acrossrun,err,testandsummary. I'll open a PR against develop.@ryanduguid, if you'd rather open it yourself, say so and I'll review it instead.
KuSh commentedon Oct 8, 2026
@bharvey42 should already be fixed by #4103. I'll rebase it to make it mergeable again
refactor(core): make MSYS-safe child argument encoding unforgettable
4 remaining items
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
KuSh commentedon Oct 10, 2026
Thanks @bharvey42, and for closing #4486. The rebased #4103 already copies the binary with
std::fs::copy(rtk().get_program(), &program), so the isolation scan passes.For the two cases you hit on 0.51.0, #4103 now has
cmd_scripts_keep_a_quoted_ampersand_and_their_exit_code:echo "a & b">> out.txt & exit 7throughrun -c,run --shell cmd -canderr/test/summary --shell cmdmust append exactly"a & b"to the file and exit 7. It passes on windows-latest.Your argv probe is still welcome on top of that: it runs a real argv-printing child on a Git Bash / windows-gnu setup, which the CI test doesn't.
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable