本帖最后由 aa77dd@163.com 于 2016-9-7 06:49 编辑
这个方式好象能支持比 choice 更多的字符, 比如 , . / Tab 字符, 甚至组合键 Ctrl+A Ctrl+Q 等
另外, 我把参数稍改了下, 在 win7 64 位仍能行- xcopy /w . . 2^>NUL
- 或者
- xcopy /w \ \ 2^>NUL
复制代码 我能找到的最早出处
February 07, 2013, 03:07:23 AM
jeb @ www.computerhope.com
http://www.computerhope.com/forum/index.php/topic,135713.msg872140.html?PHPSESSID=70a491e69021f3e926539660fee754b9#msg872140
随后, jeb 又在 stackoverflow 和 groups.google.com/forum 都发表过此代码应用例
http://stackoverflow.com/questio ... r/15160168#15160168
https://groups.google.com/forum/ ... atch.nt/hpNOPhNfwtI
我找到的时间最早的示例代码- @echo off
- setlocal EnableDelayedExpansion
- if "%~1"==":::" goto :spinnerThread
-
- :menuLoop
- <nul set /p menu=Select menu[1 or 2]=
- call :GetKey
- echo(
- echo Pressed '!key!'
- if !key!==1 call :menu1
- if !key!==2 call :menu2
- if !key!==2 call :menu2
- goto :menuLoop
-
- :menu1
- :menu2
- call :spinnerStart
- rem do some work
- ping localhost -n 3 > nl
- call :spinnerStop
- echo Finished
- exit /b
-
- :spinnerStart
- del spinnerStop.tmp > nul 2>&1
- start /b "" cmd /c "%~df0" :::
- exit /b
-
- :spinnerStop
- echo dummy > spinnerStop.tmp
- :__spinnerStop
- if exist spinnerStop.tmp goto :__spinnerStop
- exit /b
-
- :spinnerThread
- for /f %%a in ('copy /Z "%~f0" nul') do set "CR=%%a"
- set "spinChars=\|/-"
-
- :spinnerLoop
- set /a "spinner=(spinner + 1) %% 4"
- <nul set /p ".=Waiting...!spinChars:~%spinner%,1!!CR!"
- ping localhost -n 2 > nul 2>&1
- if not exist spinnerStop.tmp goto :spinnerLoop
- del spinnerStop.tmp > nul 2>&1
- echo(
- exit /b
-
- :GetKey
- set "key="
- for /F "usebackq delims=" %%L in (`xcopy /L /w "%~f0" "%~f0" 2^>NUL`) do (
- if not defined key set "key=%%L"
- )
- set "key=%key:~-1%"
- exit /b
复制代码
|