Skip to content

Commit 6c93e5b

Browse files
committed
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: #29417
1 parent f2c573c commit 6c93e5b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

tools/msvs/find_python.cmd

Lines changed: 10 additions & 8 deletions
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)