File 批量可';t为变量输入空格

File 批量可';t为变量输入空格,file,variables,batch-file,space,File,Variables,Batch File,Space,当我输入消息时,如果我输入一个空格,为什么它会崩溃 守则: :chatter cls echo type /help to see chat commands echo please use: _ instead of spaces(the problem of this code). set /p message="enter message: " if %message%==/help goto chatcmds if %message%==/exit goto chatcmds if %m

当我输入消息时,如果我输入一个空格,为什么它会崩溃

守则:

:chatter
cls
echo type /help to see chat commands
echo please use: _ instead of spaces(the problem of this code).
set /p message="enter message: "
if %message%==/help goto chatcmds
if %message%==/exit goto chatcmds
if %message%==/changeuser goto chatcmds
echo [%username%]: %message% >> %joinedchat%.chat
goto chatter
我只是不明白它不起作用的原因。
我尝试了其他人的建议,但都不起作用。

您需要将var和值括在引号中,因为空格是命令分隔符。我按照注释中的建议添加了/I开关,以进行不区分大小写的字符串比较

if /I "%message%"=="/help" goto chatcmds
if /I "%message%"=="/exit" goto chatcmds
if /I "%message%"=="/changeuser" goto chatcmds

将<代码> /i <代码>选项添加到<代码>如果命令可能是一个好主意。@戴维:考虑在双引号中包含路径/文件名。(除非确定文件/路径不能包含空格和/或特殊字符。)