From 106fdfbbf646518735830fabf7ef50b6225fa832 Mon Sep 17 00:00:00 2001 From: kana001-bit <288527232+kana001-bit@users.noreply.github.com> Date: Thu, 29 Oct 2026 18:31:06 +0900 Subject: [PATCH] fix(win): resolve relative file that exists in the process cwd 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 --- src/win/path_util.cc | 2 +- src/windowsTerminal.test.ts | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/win/path_util.cc b/src/win/path_util.cc index 764c0330c..c162e8037 100644 --- a/src/win/path_util.cc +++ b/src/win/path_util.cc @@ -55,7 +55,7 @@ std::wstring get_shell_path(std::wstring filename) { std::wstring shellpath; if (file_exists(filename)) { - return shellpath; + return filename; } wchar_t* buffer_ = new wchar_t[MAX_ENV]; diff --git a/src/windowsTerminal.test.ts b/src/windowsTerminal.test.ts index 5aa6c843a..a5f9eb186 100644 --- a/src/windowsTerminal.test.ts +++ b/src/windowsTerminal.test.ts @@ -239,6 +239,28 @@ if (process.platform === 'win32') { }); }); + describe('relative file', () => { + it('should resolve a file that also exists in the process cwd', function (done) { + this.timeout(10000); + const originalCwd = process.cwd(); + process.chdir(path.join(process.env.windir!, 'System32')); + let term: WindowsTerminal; + try { + term = new WindowsTerminal('cmd.exe', '/C echo hello', { useConptyDll }); + } finally { + process.chdir(originalCwd); + } + let result = ''; + term.on('data', (data) => { + result += data; + }); + term.on('exit', () => { + assert.ok(result.indexOf('hello') >= 0); + done(); + }); + }); + }); + describe('connect failure', () => { it('should emit exit instead of an uncaught exception when CreateProcessW fails', function (done) { this.timeout(10000);