Skip to content

fix(desktop): resolve the terminal shell to an absolute path on Windows - #706

Merged
ace331 merged 2 commits into
mainfrom
fix/windows-terminal-shell
Sep 17, 2026
Merged

ace331 merged 2 commits into
mainfrom
fix/windows-terminal-shell

Conversation

@ace331

@ace331 ace331 commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

portable-pty passes the program to CreateProcessW as lpApplicationName, and Win32 does not search PATH for that parameter. resolve_shell handed over the bare fallback names (pwsh.exe -> powershell.exe -> cmd.exe) and skipped validation for them, so a machine without PowerShell 7 on PATH got os error 2 ("The system cannot find the file specified") for every terminal tab, surfaced as terminal.json's createFailed ("无法启动终端").

Resolve each Windows candidate to an absolute path that exists before it is offered - PATH in the OS's own order (tolerating quoted entries) with the usual launch extensions, then the well-known install locations (%ProgramFiles%\PowerShell\7\pwsh.exe, System32\WindowsPowerShell\v1.0\ powershell.exe, System32\cmd.exe / %COMSPEC%) - and fall through to the next candidate instead of spawning a name that cannot be launched. list_shells reports the same absolute paths. Unix behaviour is unchanged.

The regression is pinned by terminal::shell::windows_tests; the resolver itself takes the environment as a parameter so those rules are testable without mutating the process PATH.

`portable-pty` passes the program to `CreateProcessW` as `lpApplicationName`,
and Win32 does not search `PATH` for that parameter. `resolve_shell` handed
over the bare fallback names (`pwsh.exe` -> `powershell.exe` -> `cmd.exe`) and
skipped validation for them, so a machine without PowerShell 7 on `PATH` got
`os error 2` ("The system cannot find the file specified") for every terminal
tab, surfaced as `terminal.json`'s `createFailed` ("无法启动终端").

Resolve each Windows candidate to an absolute path that exists before it is
offered - `PATH` in the OS's own order (tolerating quoted entries) with the
usual launch extensions, then the well-known install locations
(%ProgramFiles%\PowerShell\7\pwsh.exe, System32\WindowsPowerShell\v1.0\
powershell.exe, System32\cmd.exe / %COMSPEC%) - and fall through to the next
candidate instead of spawning a name that cannot be launched. `list_shells`
reports the same absolute paths. Unix behaviour is unchanged.

The regression is pinned by `terminal::shell::windows_tests`; the resolver
itself takes the environment as a parameter so those rules are testable
without mutating the process `PATH`.
@ace331
ace331 enabled auto-merge (squash) September 17, 2026 11:09
@ace331
ace331 merged commit 97d0d99 into main Sep 17, 2026
12 checks passed
@ace331
ace331 deleted the fix/windows-terminal-shell branch September 17, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant