在提示中输入空间使批处理文件崩溃

时间:2015-03-01 10:06:34

标签: windows batch-file syntax cmd

我正在努力完成无聊的命令行复制,我有一个问题。这是我的代码:

@echo off
set /a secret=1
color B
title Subnet Access v1.0
echo   ____________________________________________________________
echo  /                                                            I
echo I                     Subnet Access v1.0                      I
echo I____________________________________________________________/
echo.
echo.
timeout 3 > NUL
echo sys rev init
timeout 1 >NUL
echo loading keyframes
echo please wait
timeout 5 >NUL
echo. 
echo. 
echo Checking for alerts
timeout 6 >NUL
echo alert 0-21-77
timeout 1 >NUL
echo. 
set /p pid=enter pid: || set pid=empty

IF "%pid%"=="1123321231" (
    echo.
    set /a "secret+=1"
    cls
    echo Secrets %secret%/10 found.
    timeout 3 >NUL
    cls
    echo.
    echo pid confirmed
    timeout 1 >NUL
    echo checking with server...
    timeout 5 >NUL
    cls
    color C
    echo COULD NOT IDENTIFY
    timeout 1 >NUL
    cls
    echo.
    timeout 1 >NUL
    cls
    echo COULD NOT IDENTIFY
    timeout 1 >NUL
    cls
    echo.
    timeout 1 >NUL
    cls
    echo COULD NOT IDENTIFY
    timeout 1 >NUL
    cls
    echo.
    timeout 1 >NUL
    goto :unidentify
    )
IF NOT "%pid%"=="1123321231" GOTO :unidentify
:unidentify
cls
echo. 
echo unauthorized access
timeout 3 >NUL
echo level drop
timeout 1 >NUL
echo dropping...
timeout 3 >NUL
echo level now 0
timeout 4 >NUL
echo sys exit
timeout 1 >NUL
cls
cls
set su=0
color 7
title sys/rev/console-override
echo Subnet Console v0.1
echo Made by Murtaugh
echo.
:sub01                                       ::PROBLEM STARTS HERE
IF %su%==0 (
set /p commandMur=sys/dev/: #^> || set commandMur=emptycom
)
IF %su%==1 (
    color B
set /p commandMur=sys/dev/: $^> || set commandMur=emptycom
    )
IF %commandMur%==help (
    ::help segment
    echo.
    echo Help v0.1 Alpha by Murtaugh
    echo.
    echo Commands are listed below:
    echo dir - Lists your directory's contents.
    echo help - Shows this page.
    echo connect - Connects you to an IP address.
    echo.
    goto :sub01
    )
IF "%commandMur%"=="exit" (
    goto :eof
    )
IF "%commandMur%"=="cls" (
    cls
    goto :sub01
    )
IF "%commandMur%"=="su" IF "%su%"=="0" (
    cls
    echo.
    set /a "secret+=1"
    echo Secrets %secret%/10 found.
    set su=1
    goto :sub01
    )
IF "%commandMur%"=="su" IF "%su%"=="1" (
    goto :sub01
    )
IF "%commandMur%"=="emptycom" (
    goto :sub01
    )
IF NOT "%commandMur%"=="exit" IF NOT "%commandMur%"=="help" IF NOT "%commandMur%"=="cls" IF NOT "%commandMur%"=="su" (
    echo "%commandMur%": Bad command or file name
    echo.
    goto :sub01
    ) ::PROBLEM ENDS HERE

但是当我用空格输入内容时,它会显示test==exit was unexpected at this time.并且只是关闭。无论如何我可以解决这个问题吗?感谢。

编辑:尝试"%prompt%"=="test"事,不起作用。

2 个答案:

答案 0 :(得分:2)

test==exit was unexpected ...if的典型语法错误(set不会出现此类错误)。

很可能你有一个if %command%==exit ... - 命令下一行。要避免语法错误,请写if "%command%"=="exit" ...

答案 1 :(得分:0)

我不是一个优秀的程序员,但是当你输入带空格的文本时,尝试添加“QUOTATION TAGS”,因为批处理有时会对这些空格感到困惑