CHOOSE.EXE替换

时间:2015-11-10 08:39:30

标签: windows batch-file

请考虑我的旧剧本:

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 a q (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位是有问题的,我需要用另一个执行相同功能的命令替换它。

我该怎么做?

3 个答案:

答案 0 :(得分:1)

您应该查看DOS本机choice命令。这样的事情应该有效:

choice /c:ynq /t:7 /d:n
IF errorlevel==...

/d:n是必需的,并在7秒后将默认值设置为n。否则/t无法使用。

答案 1 :(得分:1)

您可以使用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

答案 2 :(得分:0)

阅读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 a q (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 a q (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.

errorlevel(零)值进行0测试非常重要,因为 Ctrl + C 会带来另一个对话Terminate batch job (Y/N)?和< / p>

  • Y
  • 时终止所有脚本(批处理作业)而不是choice命令
  • Nerrorlevel设置为0(零),然后脚本继续。