2010-09-15 60 views
4

我正在为我的学校LAN网络设计一个聊天工具,它会将您的邮件输入到一个.dll文件中以掩饰聊天记录。为什么批处理文件会崩溃?

问题是,突然间,每当我开始输入其中有空格的消息时,批处理文件就会崩溃。例如,如果我输入消息为“H H”批次将与错误崩溃:

h==exit was unexpected at this time

继承人的脚本:

@echo off 
CLS 
COLOR f2 
SET user=%username% 
SET message= 
IF %user%==Josh SET cuser=Miltzi & GOTO :admin 
IF %user%==miltzj SET cuser=Miltzi & GOTO :admin 
IF %user%==steinj SET cuser=Jarod & GOTO :first 
IF %user%==steinda SET cuser=Daniel & GOTO :first 
IF %user%==rubine SET cuser=Evan & GOTO :first 
IF %user%==sklairn SET cuser=Nathan & GOTO :first 
IF %user%==portnoyc SET cuser=Craig & GOTO :first 
IF %user%==polakowa SET cuser=Polly & GOTO :first 
IF %user%==selbya SET cuser=Alex & GOTO :first 
IF %user%==vanderwesthuizenl SET cuser=Lance & GOTO :first 
msg * This is a test message! :D 
REM the above line is incase a teacher runs the chat remotely from their computer 
exit 

:CHAT 
TITLE Grade 11 IT chat :) 
IF NOT EXIST C:\users\Josh\desktop\1.dll echo Chat cleared. >> C:\users\Josh\desktop\1.dll 
CLS 
type C:\users\Josh\desktop\1.dll 
SET /P message=Type message and press enter (Type help to view chat options): 
IF ERRORLEVEL 1 GOTO :CHAT 
IF %message%==exit GOTO :exit 
IF %message%==Exit GOTO :exit 
IF %message%==EXIT GOTO :exit 
IF %message%=="exit" GOTO :exit 
IF %message%==help GOTO :help 
IF %message%==Help GOTO :help 
IF %message%=="help" GOTO :help 
echo %user%: %message% >> C:\users\Josh\desktop\1.dll 
GOTO :CHAT 
:exit 
CLS 
echo %user% left the chat. >> C:\users\Josh\desktop\1.dll 
exit 
:help 
CLS 
echo Welcome to the help section 
echo To exit the chat, please type exit as a message into the chat rather than closing the cmd 

box manually. 
echo To refresh the chats messages, just press enter without writing any text. 
echo Please press enter to go back to the chat :) 
pause 
GOTO :CHAT 
:ACHAT 
TITLE Grade 11 IT chat :) 
IF NOT EXIST C:\users\Josh\desktop\1.dll echo Chat cleared. >> C:\users\Josh\desktop\1.dll 
CLS 
type C:\users\Josh\desktop\1.dll 
SET /P message=Type message and press enter (Type help to view chat options): 
IF ERRORLEVEL 1 GOTO :ACHAT 

IF %message%==exit GOTO :exit 
IF %message%==Exit GOTO :exit 
IF %message%==EXIT GOTO :exit 
IF %message%=="exit" GOTO :exit 
IF %message%==help GOTO :help 
IF %message%==Help GOTO :help 
IF %message%=="help" GOTO :help 
IF %message%==cls GOTO :CLS 

echo %user%: %message% >> C:\users\Josh\desktop\1.dll 
GOTO :CHAT 
:exit 
CLS 
echo %user% left the chat. >> C:\users\Josh\desktop\1.dll 
exit 
:help 
CLS 
echo Welcome to the help section 
echo To exit the chat, please type exit as a message into the chat rather than closing the cmd 

box manually. 
echo To refresh the chats messages, just press enter without writing any text. 
echo Please press enter to go back to the chat :) 
pause 
GOTO :CHAT 
:CLS 
del C:\users\Josh\desktop\1.dll 
GOTO :ACHAT 
:admin 
echo %user% joined the chat. >> C:\users\Josh\desktop\1.dll 
GOTO :ACHAT 
:first 
echo %user% joined the chat. >> C:\users\Josh\desktop\1.dll 
GOTO :CHAT 
exit 

任何帮助,将不胜感激!

+3

我......只是......无法用语言来形容这个。 – 2010-09-15 19:11:31

+3

基于批处理的网络聊天*?这真是太巧妙了。如果我有时间,我会复制粘贴并自己尝试。会+1,但我没有投票今天 – 2010-09-15 19:13:37

+0

哈哈..它只是因为最近修改的代码,我不能发送消息,它有一个空间...问题是,cahnged相当多,不知道是什么引起了这个问题...我记得一年前发生的同样的事情,当我做另一个网络聊天... – Josh 2010-09-15 19:17:49

回答

5

我想在这条线中发生错误:

IF %message%==exit GOTO :exit 

如果%message%包括空间,例如h h,这条线扩展到

IF h h==exit GOTO :exit 

这不是用于IF操作者的有效语法。


要避免错误,请将操作数引号:

IF "%message%"=="exit" GOTO :exit 

但要注意,这个变化也是不可靠的,将抛出一个语法错误,如果%message%包括引号字符"

顺便说一下,你可以使用/i开关执行不区分大小写字符串比较:

IF /i "%message%" EQU "exit" GOTO :exit 
+0

为避免引号字符出现问题,使用延迟扩展比扩展百分比(如果“!message!”==“exit”)也适用于引号 – jeb 2010-11-13 21:05:06

+0

Thx,它工作得很好,我的代码是'if%info%== Hi!嗨嗨,它坠毁了。现在,代码是“if/i”%info%“==”Hi!“'。 – MineCMD 2014-12-07 06:11:51

相关问题