关于cmd:Batch编程=“ set / p”将不接受空格作为答案

Batch Programming = “set /p” wont accept spaces as an answer

我知道我要问的确切问题已经有了答案,但是我试图理解该答案,或者与提出答案的人联系,但我没有走得很远。

我在说什么在这里:

没有输入时批处理" set / p"崩溃

但我不明白如何从那里的答案来修复我的代码。

下面的代码的问题是,当我按1时,它进入1answered,当我按2时,它进入2answered,当我按输入时,它进入代码的开头,但是可以,当我按 键入一个空格,然后按Enter键,代码崩溃。 回答时,请记住,我是个孩子,根本不了解代码,因此我可能不理解复杂的答案。

附言:抱歉,如果我拼错了一些东西,英语不是我的母语。

代码示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@echo off
:start
cls
set input=x

set /p input=Enter input:

if %input%==1 goto 1answered
if %input%==2 goto 2answered

echo A mistake was made
pause >NUL
goto start

:1answered
echo You entered the number 1
pause >NUL
exit

:2answered
echo You entered the number 2
pause >NUL
exit

另外,这是我正在处理的代码。
我知道它不好,但是我不知道更好:/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
@echo off

(
set /p usernameofplayer=
)<usernameofplayer.txt

set input=x

mode 85,30

color 0b

title LiteTec.inc

goto mainpage

::The code on top of mainpage is just for looks, random.

:mainpage
cls
echo.
echo var dog = ( -0.19 ) ^+ Jon / ( 0.15 ) ^* -foo(y,x,rule(destroy() ^* ROWS,920.47))
echo            /^* terminals used ^*/
echo       var num, id_var, id_func, id_idx, binaryOP, quote, assignOP;
echo this.getRandomRule = function () {
echo                if (this.rules.length == 0) {
echo                     return""
echo       WELCOME TO
echo       _      ____  ______    ___ ______    ___    __
echo      ^| ^|    ^|    ^|^|      ^|  /  _]      ^|  /  _]  /  ]
echo      ^| ^|     ^|  ^| ^|      ^| /  [_^|      ^| /  [_  /  /
echo      ^| ^|___  ^|  ^| ^|_^|  ^|_^|^|    _]_^|  ^|_^|^|    _]/  /  
echo      ^|     ^| ^|  ^|   ^|  ^|  ^|   [_  ^|  ^|  ^|   [_/   \\_
echo      ^|     ^| ^|  ^|   ^|  ^|  ^|     ^| ^|  ^|  ^|     ^\\     ^|
echo      ^|_____^|^|____^|  ^|__^|  ^|_____^| ^|__^|  ^|_____^|^\\____^|
echo.
echo         For help type"help" and click enter
echo.
goto command




:command
set /p input=#%usernameofplayer%^>

if %input%==reset goto mainpage
if %input%==help goto help
if %input%==chat goto chat
if %input%==access goto accessnotspecified
if %input%==x goto command
if %input%==ELSE goto command



:help
echo.
echo ================================================================
echo To use a command, type in its name and click enter
echo To learn sub commands of a command, type the command
echo with [] at the end
echo example: command[]
echo To use a sub command of a command, type the sub command
echo in the [] of the command
echo List of commands available:
echo =reset
echo =chat
echo =access
echo =
echo ================================================================
goto command




:accessnotspecified
echo.
echo What to access is not specified
echo.
goto command


我建议将命令部分更改为此:

1
2
3
4
5
6
7
8
9
:command
Set"input="
Set /P"input=#%usernameofplayer%>"

If /I"%input%"=="reset" GoTo mainpage
If /I"%input%"=="help" GoTo help
If /I"%input%"=="chat" GoTo chat
If /I"%input%"=="access" GoTo accessnotspecified
GoTo command

…如您所见,在输入提示双引号时,无需转义>

另外,您还可以将主页的某些部分更改为:

1
2
Echo var dog = ( -0.19 ) + Jon / ( 0.15 ) * -foo(y,x,rule(destroy() * ROWS,920.47))
Echo            /* terminals used */

…因为不需要转义+*