批处理文件不断重复set / p语句

时间:2015-01-22 20:51:43

标签: batch-file

我正在写一个批处理文件来尝试做一些事情。喜欢作为助手或其他什么。所以我开始改变颜色,但我甚至无法达到,因为set / p语句不断重复它的自我。

@echo off
title Edmond
set "action="
goto :aCheck
:aPrompt
set /p "action=What shall I do for you master?"
:aCheck
if not defined a goto :aPrompt
echo %a%


if /i "%action%" == "color" (
    echo stuff
    :cl
    set /p BC=What Should the background color be?
    set /p FC=and the foreground color?

    if %BC%==Black (
        set BC1=0
    ) else if %BC%==Blue (
        set BC1=1
    ) else if %BC%==Green (
        set BC1=2
    ) else if %BC%==Aqua (
        set BC1=3
    ) else if %BC%==Red (
        set BC1=4
    ) else if %BC%==Purple (
        set BC1=5
    ) else if %BC%==Yellow (
        set BC1=6
    ) else if %BC%==White (
        set BC1=7
    ) else if %BC%==Gray (
        set BC1=8
    ) else if %BC%==LBlue (
        set BC1=9
    ) else if %BC%==LGreen (
        set BC1=a
    ) else if %BC%==LAqua (
        set BC1=b
    ) else if %BC%==LRed (
        set BC1=c
    ) else if %BC%==LPurple (
        set BC1=d
    ) else if %BC%==LYellow (
        set BC1=e
    ) else if %BC%==LWhite (
        set BC1=f
    ) else (
        echo I'm sorry, I didn't exactly understand that.
        echo By any chance could you say it again?
        goto cl
    )

    if %FC%==Black (
        set FC1=0
    ) else if %FC%==Blue (
        set FC1=1
    ) else if %FC%==Green (
        set FC1=2
    ) else if %FC%==Aqua (
        set FC1=3
    ) else if %FC%==Red (
        set FC1=4
    ) else if %FC%==Purple (
        set FC1=5
    ) else if %FC%==Yellow (
        set FC1=6
    ) else if %FC%==White( 
        set FC1=7
    ) else if %FC%==Gray (
        set FC1=8
    ) else if %FC%==LBlue (
        set FC1=9
    ) else if %FC%==LGreen (
        set FC1=a
    ) else if %FC%==LAqua (
        set FC1=b
    ) else if %FC%==LRed (
        set FC1=c
    ) else if %FC%==LPurple (
        set FC1=d
    ) else if %FC%==LYellow (
        set FC1=e
    ) else if %FC%==LWhite (
        set FC1=f
    ) else (
        echo I'm sorry, I didn't exactly understand that.
    )
    echo Applying changes.
    ping localhost -n 2 >nul
    color %FC%%BC%
) else (
    echo I'm sorry, I didn't exactly understand that.
)
pause
exit

有人介意帮助我吗?

1 个答案:

答案 0 :(得分:1)

您在if not defined进行了无效的测试(两者都使用了您最初发布的a,因为您没有定义a,并且使用您的代码目前已根据我的评论发布了您在if not defined action a}测试的内容。

您需要测试if not defined action,如此处所示(我已经添加了原始代码中没有的pause,因此您可以看到它是否超过了测试或不 - 通过不输入值然后输入一个来测试它。

@echo off
title Edmond
set "action="
goto :Check
:Prompt
set /p "action=What shall I do for you master?"
:Check
if not defined action goto :Prompt
echo %action%
pause