Skip to content

Commit 7bff962

Browse files
joaocgreisTrott
authored andcommitted
build,win: fix Python detection on localized OS
This code previously assumed the default value was always printed to the console by reg.exe as "(default)", but this is not true on localized versions of Windows and can contain spaces. Fixes: nodejs#29417 PR-URL: nodejs#29423 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: David Carlier <[email protected]>
1 parent 2882ce9 commit 7bff962

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
test/fixtures/* -text
22
vcbuild.bat text eol=crlf
3+
tools/msvs/find_python.cmd text eol=crlf

tools/msvs/find_python.cmd

+10-8
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ exit /b 1
6060
:: Read the InstallPath of a given Environment Key to %p%
6161
:: https://www.python.org/dev/peps/pep-0514/#installpath
6262
:read-installpath
63-
:: %%a will receive token 3
64-
:: %%b will receive *, corresponding to token 4 and all after
65-
for /f "skip=2 tokens=3*" %%a in ('reg query "%1\InstallPath" /ve /t REG_SZ 2^> nul') do (
66-
set "head=%%a"
67-
set "tail=%%b"
68-
set "p=!head!"
69-
if not "!tail!"=="" set "p=!head! !tail!"
70-
exit /b 0
63+
:: %%a will receive everything before ), might have spaces depending on language
64+
:: %%b will receive *, corresponding to everything after )
65+
:: %%c will receive REG_SZ
66+
:: %%d will receive the path, including spaces
67+
for /f "skip=2 tokens=1* delims=)" %%a in ('reg query "%1\InstallPath" /ve /t REG_SZ 2^> nul') do (
68+
for /f "tokens=1*" %%c in ("%%b") do (
69+
if not "%%c"=="REG_SZ" exit /b 1
70+
set "p=%%d"
71+
exit /b 0
72+
)
7173
)
7274
exit /b 1
7375

0 commit comments

Comments
 (0)