请考虑我的旧脚本:
CHOOSE.EXE /c:ynq /t:n,7 " until 7 seconds press Y to smooth details " set "LowPassFilter=0" if errorlevel==255 echo No such choice (255) if not errorlevel==4 if errorlevel==3 echo The choice was aq (3) if not errorlevel==3 if errorlevel==2 echo LowPass OFF if not errorlevel==2 if errorlevel==1 (Set LowPassFilter=1) if not errorlevel==1 if errorlevel==0 echo The choice was interrupted (0) IF "%LowPassFilter%"=="1" echo LowPassFiltering ATTIVATO per ammorbidire contorni IF "%LowPassFilter%"=="1" Set "filteringVirtualdubMode=135" IF "%LowPassFilter%"=="0" echo LowPassFiltering Disattivato IF "%LowPassFilter%"=="0" Set "filteringVirtualdubMode=7"
但select.exe是有问题的Windows 10 64位,我需要用另一个执行相同function的命令replace它。
我该怎么做?
你应该看看DOS本地choice
命令。 像这样的东西应该工作:
choice /c:ynq /t:7 /d:n IF errorlevel==...
/d:n
是必需的,并在7秒后将缺省值设置为n
。 否则/t
不能使用。
你可以使用XCOPY
,它可以处理比choice
更多的字符。
唯一的缺点是实现超时更复杂
@echo off setlocal EnableDelayedExpansion call :getKey echo '!ch!' exit /b :getKey set "ch=" setlocal DisableDelayedExpansion for /f "delims=" %%C in ('2^>nul xcopy /w /l "%~f0" "%~f0"') do if not defined ch set "ch=%%C" ( endlocal set "ch=^%ch:~-1%" ! ) exit /b
阅读choice /?
。 使用
choice /c:ynq /t:7 /D:n /M:"until 7 seconds press Y to smooth details"
为了处理错误errorlevel
,请阅读if /?
。 请注意, if errorlevel ...
命令的连续性很重要(需要按降序测试errorlevel
值)。
choice /c:ynq /t:7 /D:n /M:"until 7 seconds press Y to smooth details" set "LowPassFilter=0" if errorlevel 255 echo No such choice (255)&goto :next if errorlevel 3 echo The choice was aq (3)&goto :next if errorlevel 2 echo LowPass OFF&goto :next if errorlevel 1 (Set "LowPassFilter=1"&goto :next) if errorlevel 0 echo The choice was interrupted (0) :next IF "%LowPassFilter%"=="1" ( echo LowPassFiltering ATTIVATO per ammorbidire contorni Set "filteringVirtualdubMode=135" ) IF "%LowPassFilter%"=="0" ( echo LowPassFiltering Disattivato Set "filteringVirtualdubMode=7" )
另一种方法(你可以在下一个代码片段中以任何顺序测试%errorlevel%
值):
SETLOCAL EnableExtensions choice /c:ynq /t:7 /D:n /M:"until 7 seconds press Y to smooth details" set "LowPassFilter=0" if %errorlevel% EQU 255 echo No such choice (255) if %errorlevel% EQU 3 echo The choice was aq (3) if %errorlevel% EQU 2 echo LowPass OFF if %errorlevel% EQU 1 (Set "LowPassFilter=1") if %errorlevel% EQU 0 echo The choice was interrupted (0) rem etc.
对于0
(零)值,测试错误errorlevel
很重要,因为Ctrl + C会带来另一个对话Terminate batch job (Y/N)?
和
Y
终止所有脚本(批处理作业)而不是choice
命令 N
将errorlevel
设置为0
(零),脚本继续。