有没有办法在批处理中使用多行用户输入提示?

发布于 2025-02-08 18:35:10 字数 505 浏览 0 评论 0原文

我一直在尝试制作一个用户输入提示,该提示显示自身作为多行。

我希望它看起来的示例:

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

这就是我尝试这样做的方式:

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

但是当我运行它时,它会像这样

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

谷歌搜索,但是我找不到任何帮助的东西,所以如果有人可以告诉我一个做到这一点的方法!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ㄟ。诗瑗 2025-02-15 18:35:10

也许很简单。

@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=

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=
梦亿 2025-02-15 18:35:10

有一种方法可以做到这一点,也就是创建LineFeed变量。

set/p版本:

@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

choce.exe版本 (推荐)

@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

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]
quot; 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文