-1

I've been trying to make a user input prompt that displays itself as multiple lines.

Example of how I want it to look:

Welcome to the program!
What would you like to do?
option [1]
option [2]
option [3]

This is how I tried to do that:

set /p selection="Welcome to the program! ^ What would you like to do? ^ option [1] ^ option [2] ^ option [3]"

But when I run that, it comes out like this:

Welcome to the program!  What would you like to do?  option [1]  option [2]  option [3]

I googled it but I couldn't find anything that helped, so if someone could tell me a way to do this that would be great!

  • 1
    several `echo` commands – jsotola Jun 20 '22 at 02:02
  • 1
    Try using the `search` facility for `[batch]menu` – Magoo Jun 20 '22 at 02:12
  • Please read my answer on [How to stop Windows command interpreter from quitting batch file execution on an incorrect user input?](https://stackoverflow.com/a/49834019/3074564) Do not use `set /P` for a choice menu. There is the command __CHOICE__ available since Windows Vista and Windows Server 2003 for choice menus. – Mofi Jun 20 '22 at 11:07

2 Answers2

1

Maybe it's simple.

@echo off
echo welcome to program!
echo what would you like to do?
echo option[1]
echo option[2]
echo option[3]

set /p selection=
Freeman
  • 36
  • 5
1

There is a way to do it, and that is by creating a linefeed variable.

SET /P version:

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

Rem Define linefeed as a variable.
(Set BR=^
%NULL%
)

:AskIt
Set "VARIABLE="
Rem Delayed expansion is needed to use the linefeed variable.
SetLocal EnableDelayedExpansion
Set /P "VARIABLE=Welcome to the program^!!BR!What would you like to do?!BR!option [1]!BR!option [2]!BR!option [3]!BR!"
(Set VARIABLE) 2>NUL | %SystemRoot%\System32\findstr.exe /RX "^VARIABLE=[123]$" 1>NUL || GoTo AskIt
Echo You chose %VARIABLE%& Pause

EndLocal

CHOICE.EXE version (recommended)

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

Rem Define linefeed as a variable.
(Set BR=^
%NULL%
)

Rem Delayed expansion is needed to use the linefeed variable.
SetLocal EnableDelayedExpansion
%SystemRoot%\System32\choice.exe /C 123 /N /M "Welcome to the program^!!BR!What would you like to do?!BR!option [1]!BR!option [2]!BR!option [3]!BR!"
Echo You chose %ERRORLEVEL%& Pause

EndLocal
Compo
  • 36,585
  • 5
  • 27
  • 39