Skip to content

terminal: Fix double quoting of commands on Windows cmd.exe - #47534

Merged
Veykril merged 1 commit into
zed-industries:mainfrom
lingyaochu:python_debugger
Jan 26, 2026
Merged

terminal: Fix double quoting of commands on Windows cmd.exe#47534
Veykril merged 1 commit into
zed-industries:mainfrom
lingyaochu:python_debugger

Conversation

@lingyaochu

@lingyaochu lingyaochu commented Jan 24, 2026

Copy link
Copy Markdown
Collaborator

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.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jan 24, 2026

@Veykril Veykril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@Veykril

Veykril commented Jan 26, 2026

Copy link
Copy Markdown
Member

/cherry-pick preview

@Veykril
Veykril enabled auto-merge (squash) January 26, 2026 07:15
@Veykril
Veykril merged commit 7af276a into zed-industries:main Jan 26, 2026
30 checks passed
github-actions Bot pushed a commit that referenced this pull request Jan 26, 2026
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`.
zed-zippy Bot added a commit that referenced this pull request Jan 26, 2026
…(cherry-pick to preview) (#47627)

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:


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`.

Co-authored-by: Xin Zhao <zx0@mail.ustc.edu.cn>
@lingyaochu
lingyaochu deleted the python_debugger branch January 27, 2026 09:55
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
…stries#47534)

Closes zed-industries#47303 

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

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

And a month ago, PR zed-industries#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 zed-industries#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`.
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…stries#47534)

Closes zed-industries#47303 

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

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

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

https://github.com/zed-industries/zed/blob/6db670859a7f438b3aaa49191e267fd93cf32247/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 zed-industries#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`.
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.

Windows Debugpy launcher fails to connect with virtual environment toolchain

2 participants