C:\>CHOICE /?
CHOICE [/C choices] [/N] [/CS] [/T timeout /D choice] [/M text]
Description:This tool allows users to select one item from a listof choices and returns the index of the selected choice.
Parameter List:/C choices Specifies the list of choices to be created.Default list is "YN".
/N Hides the list of choices in the prompt.The message before the prompt is displayedand the choices are still enabled.
/CS Enables case-sensitive choices to be selected.By default, the utility is case-insensitive.
/T timeout The number of seconds to pause before a defaultchoice is made. Acceptable values are from 0 to9999. If 0 is specified, there will be no pauseand the default choice is selected.
/D choice Specifies the default choice after nnnn seconds.Character must be in the set of choices specifiedby /C option and must also specify nnnn with /T.
/M text Specifies the message to be displayed beforethe prompt. If not specified, the utilitydisplays only a prompt.
/? Displays this help message.
NOTE:The ERRORLEVEL environment variable is set to the index of thekey that was selected from the set of choices. The first choicelisted returns a value of 1, the second a value of 2, and so on.If the user presses a key that is not a valid choice, the toolsounds a warning beep. If tool detects an error condition,it returns an ERRORLEVEL value of 255. If the user pressesCTRL+BREAK or CTRL+C, the tool returns an ERRORLEVEL valueof 0. When you use ERRORLEVEL parameters in a batch program, listthem in decreasing order.
Examples:CHOICE /?CHOICE /C YNC /M "Press Y for Yes, N for No or C for Cancel."CHOICE /T 10 /C ync /CS /D yCHOICE /C ab /M "Select a for option 1 and b for option 2."CHOICE /C ab /N /M "Select a for option 1 and b for option 2."
@ECHO OFFREM DELAY seconds
REM GET ENDING SECONDFOR /F "TOKENS=1-3 DELIMS=:." %%A IN ("%TIME%") DO SET /A H=%%A, M=1%%B%%100, S=1%%C%%100, ENDING=(H*60+M)*60+S+%1
REM WAIT FOR SUCH A SECOND:WAITFOR /F "TOKENS=1-3 DELIMS=:." %%A IN ("%TIME%") DO SET /A H=%%A, M=1%%B%%100, S=1%%C%%100, CURRENT=(H*60+M)*60+SIF %CURRENT% LSS %ENDING% GOTO WAIT
@echo offecho.if "%1"=="" goto askqif "%1"=="/?" goto helpif /i "%1"=="/h" goto helpif %1 GTR 0 if %1 LEQ 9999 if /i "%2"=="/q" set ans1=%1& goto quietif %1 GTR 0 if %1 LEQ 9999 set ans1=%1& goto breakoutif %1 LEQ 0 echo %1 is not a valid number & goto helpif not "%1"=="" echo.&echo "%1" is a bad parameter & goto helpgoto end
:helpecho SLEEP runs interactively (by itself) or with parameters (sleep # /q )echo where # is in seconds, ranges from 1 - 9999echo Use optional parameter /q to suppress standard outputecho or type /h or /? for this help fileecho.goto end
:askqset /p ans1=How many seconds to sleep? ^<1-9999^>echo.if "%ans1%"=="" goto askqif %ans1% GTR 0 if %ans1% LEQ 9999 goto breakoutgoto askq
:quietchoice /n /t %ans1% /d n > nulif errorlevel 1 ping 1.1.1.1 -n 1 -w %ans1%000 > nulgoto end
:breakoutchoice /n /t %ans1% /d n > nulif errorlevel 1 ping 1.1.1.1 -n 1 -w %ans1%000 > nulecho Slept %ans1% second^(s^)echo.
:end
for /f "tokens=1,2,3,4 delims=:," %%A in ("%TIME%") do set /a HH=%%A, MM=1%%B-100, SS=1%%C-100, CC=1%%D-100, TBASE=((HH*60+MM)*60+SS)*100+CC
:: Example delay 1 seg.set /a TFIN=%TBASE%+100
:ESPERARfor /f "tokens=1,2,3,4 delims=:," %%A in ("%TIME%") do set /a HH=%%A, MM=1%%B-100, SS=1%%C-100, CC=1%%D-100, TACTUAL=((HH*60+MM)*60+SS)*100+CC
if %TACTUAL% lss %TBASE% set /a TACTUAL=%TBASE%+%TACTUAL%if %TACTUAL% lss %TFIN% goto ESPERAR
<Target Name="TestCmd"><Exec Command="choice /C YN /D Y /t 5 " /></Target>
结果在:
TestCmd:choice /C YN /D Y /t 5
EXEC : error : The file is either empty or does not contain the valid choices. [test.proj][Y,N]?C:\test.proj(5,9): error MSB3073: The command "choice /C YN /D Y /t 5 " exited with code 255.
TestCmd:timeout /t 5EXEC : error : Input redirection is not supported, exiting the process immediately. [test.proj]C:\test.proj(5,7): error MSB3073: The command "timeout /t 5 " exited with code 1.
@echo off
set SW=00
set SW2=00
set /a Sec=%1-1
set il=00@echo Wait %1 secondfor /f "tokens=1,2,3,4 delims=:," %%A in ("%TIME%") do set /a HH=%%A, MM=1%%B-100, SS=1%%C-100, CC=1%%D-100, TBASE=((HH*60+MM)*60+SS)*100+CC, SW=CC
set /a TFIN=%TBASE%+%100
:ESPERARfor /f "tokens=1,2,3,4 delims=:," %%A in ("%TIME%") do set /a HH=%%A, MM=1%%B-100, SS=1%%C-100,
CC=1%%D-100, TACTUAL=((HH*60+MM)*60+SS)*100+CC, SW2=CC
if %SW2% neq %SW% goto notypeif %il%==0 (echo Left %Sec% second & set /a Sec=sec-1 & set /a il=il+1)goto no0:notypeset /a il=0:no0
if %TACTUAL% lss %TBASE% set /a TACTUAL=%TBASE%+%TACTUAL%if %TACTUAL% lss %TFIN% goto ESPERAR