Today I read this SO question entitled "ask set /p variable on a different line" that request to get user input with this format:
Code: Select all
enter your name
name:_(input would be here)
enter name above
I remembered timeout behavior and after several tests I discovered that when timeout is started in a separate cmd.exe session (i.e. at any side of a pipeline or in a FOR /F command), then the "previous" cursor position is lost and timeout show the seconds countdown at screen home (position 0,0)! I used this behavior to develop the program below:
Code: Select all
@echo off
setlocal
cls
echo/
echo Enter your name
echo First:
echo Enter first name above
echo/
echo Last:
echo Enter last name above
rem Move cursor to one line below screen size,
rem you must adjust this value to fit your screen.
for /L %%i in (1,1,30) do echo/
rem The line below do this:
rem 1. Show "Waiting for 1 seconds, press a key..." at current line.
rem 2. Move cursor to screen home (position 0,0) and show a "0" there;
rem this scrolls screen contents and previous "Waiting" line disappear.
rem 3. Timeout command terminate; the cursor remains at second screen line.
for /F %%a in ('timeout /T 1 ^> CON') do rem
echo/
set /P "first=First: "
echo/
echo/
set /P "last=Last: "
echo/
echo/
echo Name read: "%first% %last%"
The only disadvantage of this method is that a "0" will always appear at screen home. Tested on Windows 8.1.
Antonio