這裏的分離路徑(可能)由REG查詢返回的另一種方式,獨立於Windows版本:
- 更換隻能保證單詞的查詢結果,
REG_SZ
,具有獨特的單個字符,例如?
。 (見後面的註釋)
- 然後使用獨特的單字符,如果找到了,如果有的話在2個令牌拆分查詢結果並只獲得第二屆一個。
- 最後,修剪此類標記左側的製表符和空格以獲取路徑。
注: 問號實際上可能是一個路徑的一部分,儘管這似乎是不尋常的。理想情況下,應該是不允許的路徑字符:|
,<
,>
,等等。但其中一些給了我們麻煩逃脫他們。
檢查時還有與原代碼的另一個問題,:
if exist %PYTHONINSTALL%\whatever goto :EOF
正在檢查的路徑應包含在雙引號,考慮到含空格的路徑。
因此,總而言之,這是另一種實現方式,例如,只是爲了HKML部分:
rem Try HKLM
SET QueryResult=
FOR /F "usebackq delims=" %%r IN (`%reg% QUERY HKLM\%key% /ve 2^>NUL`) DO @SET QueryResult=%%r
SET ReplacedResult=%QueryResult:REG_SZ=?%
FOR /F "tokens=2 delims=?" %%t IN ("%ReplacedResult%") DO SET "%~1=%%t"
rem trim tabs and spaces from the left (note: there's a literal tab in next line)
FOR /F "tokens=* delims= " %%v IN ("%PYTHONINSTALL%") DO SET PYTHONINSTALL=%%v
if exist "%PYTHONINSTALL%\python.exe" goto :EOF
rem It may be a 32bit Python directory built from source, in which case the
rem executable is in the PCBuild directory.
if exist "%PYTHONINSTALL%\PCBuild\python.exe" (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild" & goto :EOF)
rem Or maybe a 64bit build directory.
if exist "%PYTHONINSTALL%\PCBuild\amd64\python.exe" (set "PYTHONINSTALL=%PYTHONINSTALL%\PCBuild\amd64" & goto :EOF)
請看看this Github commit看到實際的差異。
@Krispcheez,我仍然得到同樣的錯誤,你是如何配置你的PATH變量,實際上指向python? –
我沒得 – Krispycheez
@RicoPlasakoi,看看你是否修改activate.bat並添加你所得到的回聲%PYTHONINSTALL%後,每一個「設置PYTHONINSTALL =%PYTHONINSTALL:=%」的CheckPython – Krispycheez