无论出于何种原因,此命令都有效:
SET QUERY="heat wave"
START /d "C:\Program Files (x86)\Google\Chrome\Application" chrome.exe https://www.google.com/search?q=%QUERY: =+%
但这不是:
SET SWITCH=1
IF %SWITCH%==1 (
SET QUERY="heat wave"
START /d "C:\Program Files (x86)\Google\Chrome\Application" chrome.exe https://www.google.com/search?q=%QUERY: =+%
)
答案 0 :(得分:1)
这里的关键是去enabledelayedexpansion
setlocal enabledelayedexpansion
SET SWITCH=1
IF %SWITCH%==1 (
SET QUERY="heat wave"
START /d "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://www.google.com/search?q=!QUERY: =+!
)
有关delayedexpansion
的更多信息,请从cmdline执行set /?
。
如果没有delayedexpansion
,也可以通过将最后一个%
加倍并调用start来实现。
SET SWITCH=1
IF %SWITCH%==1 (
SET QUERY="heat wave"
call START /d "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://www.google.com/search?q=%%QUERY: =+%%
)