0

In this senario,

echo Write your name below.
echo.
set /p name="Enter here: "
echo.
echo *other text*

is there a way where the set /p name="Enter name: " doesn't pause the screen and also displays the text below.

I figured that since its a top down language it probably cannot, but there are many people on here with more experience who might no otherwise.

  • 1
    That depends entirely on whether or not you're using Windows 10. Windows 10 can use [VT100 character sequences](https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences) to move the cursor; other versions can not. – SomethingDark Feb 14 '21 at 23:17
  • @SomethingDark yes it is windows 10 – Victor Chavez Feb 14 '21 at 23:20

2 Answers2

2

If you're using Windows 10, you can use VT100 escape sequences to move the cursor up and down, printing everything first and then getting user input afterwards.

@echo off

:: Generate an escape character. Normally I'd just use ALT+027,
:: but SO doesn't display those properly.
for /f %%A in ('echo prompt $E^| cmd') do set "esc=%%A"

:: The trick here is to write out everything and then move the cursor
:: back to where it needs to be
echo Write your name below.
echo(
echo(
echo(
echo *other text*%ESC%[2A
set /p "name=Enter here: "

:: When we're done, move the cursor to where it would have been if
:: we had written everything top-down
echo %ESC%[1B
SomethingDark
  • 13,229
  • 5
  • 50
  • 55
1

You can store new line character in a variable and print it out

@echo off
setlocal EnableDelayedExpansion

(set LF=^
%=empty=%
)

echo Write your name below.
echo.
set /p name="Enter here:!LF!*other text*!LF!"
phuclv
  • 37,963
  • 15
  • 156
  • 475
  • 1
    This doesn't move the cursor back up to the `Enter here:` line – SomethingDark Feb 15 '21 at 05:48
  • @SomethingDark the OP says nothing about moving the cursor. The question is just about printing multiple lines "Enter here:" and "*other text*" – phuclv Feb 15 '21 at 06:06
  • 2
    Presumably OP is new enough to batch that they assumed that you only enter input on the line where it's requested, but they also know that text underneath that line won't normally be displayed until after the input is received. Asking how to print text on lines 1 and 5 and _then_ getting input on line 3 is the only thing that makes sense. – SomethingDark Feb 15 '21 at 06:20