【发布时间】:2016-03-21 06:38:32
【问题描述】:
我正在批量制作聊天室之类的东西。不幸的是,该文件无法存储变量。这是我的代码
@echo off
color b
Title Messanger
:top
echo Are you hosting the chat?
set /p host="Yes or no>"
if /i "%host%"=="yes" (
set /p port="Port>"
rem This would normally listen for connections
echo Listening for connections on port %port%
pause
)
if /i "%host%"=="no" (
echo Who is hosting this chat?
set /p ip="Ip>"
set /p port="Port>"
echo ----------------CHAT----------------
rem This would normally connect to the ip and port
echo %ip% %port%
)
echo Error.
pause
goto top
我不知道你是否得到相同的结果,但只看到没有变量的消息。输出:
Are you hosting the chat?
Yes or no>yes
Port>8080
Listening for connections on port
Press any key to continue . . .
在此之后,它应该会显示回显错误并转到文件的开头
【问题讨论】:
-
哪个部分不工作?我无法使用 Windows 机器,但如果你告诉我想要的结果和取得的结果,我可能仍然可以提供帮助。是
IF语句失败并且没有采取正确的路线,还是%ip%和%port%没有出现在echo中? -
它是说当变量应该占用输入的值时,它们没有任何值。编辑:刚刚看到评论的编辑。 %ip% 和 %port% 没有出现在 echo 中
-
所以
IF语句没有正确评估?或者这是有效的,是%ip%和%port%没有出现在echo中? -
也许您可以将输出添加到您的问题正文中。
-
如果有帮助,我可以添加如果我选择否的输出
标签: batch-file