Skip to content

fix(win): resolve relative file that exists in the process cwd - #1006

Open
kana001-bit wants to merge 1 commit into
microsoft:mainfrom
kana001-bit:fix/win-get-shell-path-cwd-match
Open

kana001-bit wants to merge 1 commit into
microsoft:mainfrom
kana001-bit:fix/win-get-shell-path-cwd-match

Conversation

@kana001-bit

Copy link
Copy Markdown

Fixes #1005

On Windows, spawning a shell by bare name (e.g. cmd.exe) fails with File not found: and an empty path when the calling process's current working directory contains that file, e.g. when an Electron app is launched with its cwd set to C:\Windows\System32.

Cause

path_util::get_shell_path first checks whether the relative name exists in the process cwd, but in that case it returns shellpath, which is still empty:

if (file_exists(filename)) {
  return shellpath;   // empty
}

startProcess then rejects the empty path, so the error message also shows no path.

Fix

Return filename when it exists in the cwd. The resolved path is only used for the existence check in startProcess; the process itself is still created from the command line, and the cwd is part of the normal CreateProcessW search order, so the spawn behaves the same as it does from any other cwd.

Repro

process.chdir('C:/Windows/System32');
require('node-pty').spawn('cmd.exe', [], {}); // Error: File not found:

Tests

Added a relative file test to windowsTerminal.test.ts that changes the process cwd to %windir%\System32 and spawns cmd.exe. It fails with File not found: before the fix and passes after it, with useConptyDll both false and true.

Found while debugging a downstream report in Orca: stablyai/orca#17083

🤖 Generated with Claude Code

get_shell_path returned an empty string when the relative file name
existed in the current working directory, so spawning e.g. "cmd.exe"
from a process whose cwd is C:\Windows\System32 failed with
"File not found: " and an empty path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kana001-bit

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

Windows: spawning a bare shell name fails with "File not found: " when the process cwd contains that file

1 participant