在循环中设置/p? [英] Set /p in a loop?
问题描述
这可能是不可能的,但我有一个循环,通过使用 TYPE
输入 logo_(framenumber).txt
和 framenumber
由循环决定:
This is probably impossible, but I have a loop that displays a animated logo by using TYPE
to type logo_(framenumber).txt
and the framenumber
is determined by a loop:
:s
if %m%==379 set m=0
cls
TYPE Logo_%m%.txt
set /a m=%m%+1
goto s
我希望能够使用 set /p
选项并且不会干扰/停止循环,以便在用户输入 set /p
时播放动画输入.我认为有一种方法可以用 FOR
做到这一点,但我不确定如何.有任何想法吗?谢谢.
I wanted to be able to use a set /p
option and without disturbing/stopping the loop so the animation plays while a user is typing in the set /p
input. I think there is a way to do it with FOR
but I'm not sure how. Any ideas? Thanks.
推荐答案
虽然这个话题有点老,但我才发现.这是一个运行良好的纯批处理文件解决方案:
Although this topic is somewhat old, I just discovered it. This is a pure Batch file solution that works pretty well:
编辑:我稍微修改了代码以使其更简单.
EDIT: I slightly modified the code in order to made it simpler.
@echo off
setlocal EnableDelayedExpansion
if "%1" equ "Animate" goto %1
for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"
cd . > input.txt
start "" /B "%~F0" Animate
set "input="
:nextKey
set "key="
for /F "delims=" %%K in ('xcopy /W "%~F0" "%~F0" 2^>NUL') do if not defined key set "key=%%K"
if "!key:~-1!" equ "!CR!" goto endInput
if "!key:~-1!" equ "!BS!" (
if defined input set "input=%input:~0,-1%"
) else (
set "input=%input%!key:~-1!"
)
set /P "=%input%" > input.txt < NUL
goto nextKey
:endInput
del input.txt
echo/
echo/
echo Input read: "%input%"
goto :EOF
:Animate
set "banner= Enter your name please "
set m=0
:loop
if not exist input.txt exit
set /A m=(m+1)%%51
cls
echo/
echo/ !banner:~%m%,31!
echo/
echo/
if exist input.txt (type input.txt) else exit
ping -n 1 -w 300 localhost > NUL
ping -n 1 -w 300 localhost > NUL
ping -n 1 -w 300 localhost > NUL
goto loop
在此解决方案中,动画徽标"被横幅替换,但显示一系列文件的方法实际上是相同的.
In this solution the animated "logo" is replaced by a banner, but the method to display a series of files is practically the same.
这篇关于在循环中设置/p?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!