Skip to content

terminal: Fix double quoting of commands on Windows cmd.exe (#47534) (cherry-pick to preview)#47627

Merged
zed-zippy[bot] merged 1 commit intov0.221.xfrom
cherry-pick-v0.221.x-7af276a9
Jan 26, 2026
Merged

terminal: Fix double quoting of commands on Windows cmd.exe (#47534) (cherry-pick to preview)#47627
zed-zippy[bot] merged 1 commit intov0.221.xfrom
cherry-pick-v0.221.x-7af276a9

Conversation

@zed-zippy
Copy link
Contributor

@zed-zippy zed-zippy bot commented Jan 26, 2026

Cherry-pick of #47534 to preview


Closes #47303

The command quoting for cmd shell was first introduced (at least in
this case) in PR #41216 three months ago:

let mut arg =
format!("{activation_script}{separator} {to_run}");
if shell_kind == ShellKind::Cmd {
// We need to put the entire command in quotes since otherwise CMD tries to execute them
// as separate commands rather than chaining one after another.
arg = format!("\"{arg}\"");
}
let args = shell_kind.args_for_shell(false, arg);

And a month ago, PR #42382 added command quoting for cmd in a
different place:

pub fn args_for_shell(&self, interactive: bool, combined_command: String) -> Vec<String> {
match self {
ShellKind::PowerShell | ShellKind::Pwsh => vec!["-C".to_owned(), combined_command],
ShellKind::Cmd => vec![
"/S".to_owned(),
"/C".to_owned(),
format!("\"{combined_command}\""),
],
ShellKind::Posix
| ShellKind::Nushell
| ShellKind::Fish
| ShellKind::Csh
| ShellKind::Tcsh
| ShellKind::Rc
| ShellKind::Xonsh
| ShellKind::Elvish => interactive
.then(|| "-i".to_owned())
.into_iter()
.chain(["-c".to_owned(), combined_command])
.collect(),
}
}

As a result, the command is now quoted twice when using cmd. cmd
interprets the entire double-quoted string (e.g., ""command & args"") as
a single (invalid) executable name, and this would lead to an error like
“The system cannot find the path specified” in #47303 .

The solution is to remove the redundant manual quoting in terminals.rs
and rely on the centralized logic in util/src/shell.rs.

/cc @Veykril @reflectronic

Release Notes:

  • Fixed a bug where terminal tasks failed to start on Windows when using
    cmd.exe.

Closes #47303 

The command quoting for `cmd` shell was first introduced (at least in
this case) in PR #41216 three months ago:

https://github.com/zed-industries/zed/blob/3d4582d4dc9145270650e12f9ce5a534b888f4a2/crates/project/src/terminals.rs#L202-L210

And a month ago, PR #42382 added command quoting for `cmd` in a
different place:

https://github.com/zed-industries/zed/blob/3d4582d4dc9145270650e12f9ce5a534b888f4a2/crates/util/src/shell.rs#L413-L434

As a result, the command is now quoted twice when using `cmd`. `cmd`
interprets the entire double-quoted string (e.g., ""command & args"") as
a single (invalid) executable name, and this would lead to an error like
“The system cannot find the path specified” in #47303 .

The solution is to remove the redundant manual quoting in `terminals.rs`
and rely on the centralized logic in `util/src/shell.rs`.

/cc @Veykril @reflectronic 

Release Notes:

- Fixed a bug where terminal tasks failed to start on Windows when using
`cmd.exe`.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 26, 2026
@zed-zippy zed-zippy bot merged commit b4df75d into v0.221.x Jan 26, 2026
27 checks passed
@zed-zippy zed-zippy bot deleted the cherry-pick-v0.221.x-7af276a9 branch January 26, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant