我有一个 Windows Bat 文件,并面临在执行 if 条件时设置路径命令的问题。
set browser=chrome
echo Browser value: %browser%
if "%browser%"=="chrome" (
echo "Browser passed is Chrome"
echo Chrome browser version before upgrade
reg query "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version
echo Upgrade chrome browser to the latest version
choco upgrade googlechrome -y --ignore-checksums
echo Check the exit code of googlechrome upgrade command
if %ERRORLEVEL% neq 0 (
echo "Failed to upgrade googlechrome."
exit /b 1
)
echo "Chrome browser is upgraded successfully. Chrome browser version after upgrade,"
reg query "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version
:: Install chromedriver using curl
echo "Install chromedriver from official google website"
C:
cd Users\myuser\Downloads
echo Set the installation directory
set "INSTALL_DIR=C:\Users\myuser\Downloads"
set DESTINATION_DIR=H:
echo Download latest chromeDriver for 32-bit Windows
set browserVersion=curl https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_STABLE
curl -o "%INSTALL_DIR%\chromedriver-win32.zip" https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/%browserVersion%/win32/chromedriver-win32.zip
:: Check the exit code of the chromedriver download command
if %ERRORLEVEL% neq 0 (
echo "Failed to install chromedriver."
exit /b 1
)
echo "Chromedriver installation is successful."
unzip chromedriver-win32.zip -d %DESTINATION_DIR%
echo Add the directory to the system's PATH
set PATH=%DESTINATION_DIR%\chromedriver-win32;%PATH%
echo %PATH%
H:
echo "Current chromedriver version"
chromedriver -version
) else (
echo this is else *****
)
在实际执行之前,正在执行设置路径命令。
输出是:
C:\Users\myuser>set browser=chrome
C:\Users\myuser>echo Browser value: chrome
Browser value: chrome
\<abc>\<def> was unexpected at this time.
C:\Users\myuser> set PATH=\chromedriver-win32;C:\Program Files\Docker\Docker\Resources\bin;<.... rest of the path>
C:\Users\myuser>
即使尝试使用 setx 如下并面临同样的问题, setx /M 路径“%DESTINATION_DIR