繁体   English   中英

批量颜色选择错误

[英]Batch Color Selection Error

我在批处理程序中遇到问题,我试图学习让用户输入所选择的颜色。 问题是,当我输入我想要的值并按下输入程序关闭。 我有Windows 10 64x

@echo off

:setcolor
set /p %color%= "What color text do you want? [0-White  1-Blue  2-Green  3-Red  4-Yellow]"
if %color% EQU 0 goto :1 
if %color% EQU 1 goto :2
if %color% EQU 2 goto :3
if %color% EQU 3 goto :4
if %color% EQU 4 goto :5
goto :setcolor

:1
color 07
goto :main 
:2
color 01
goto :main
:3
color 02
goto :main
:4
color 0c
goto :main
:5
color 06
goto :main

:main
echo test
pause

正如@Stephan所提到的, set /p %color%=应该更改为set /p color=

设置变量时,我们不会将% s放在变量周围(展开它),但我们输入变量的名称。

那么,这是你的代码:

@echo off

:setcolor
set /p color="What color text do you want? [0-White  1-Blue  2-Green  3-Red  4-Yellow]"
if "%color%" EQU "0" goto :1 
if "%color%" EQU "1" goto :2
if "%color%" EQU "2" goto :3
if "%color%" EQU "3" goto :4
if "%color%" EQU "4" goto :5
goto :setcolor

    .....

顺便说一句,我在%color%和数字上添加引号( " )以防止批处理文件在遇到空输入或空间输入时停止

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM