【发布时间】:2016-05-07 16:26:49
【问题描述】:
我是 Minecraft 服务器的所有者,目前正在研究一种制作自动设置脚本的方法,以便其他人可以更轻松地运行服务器。我已经完成了所有工作,但在测试时,此代码抛出“命令的语法不正确”错误。代码如下:
@ECHO OFF
SETLOCAL EnableDelayedExpansion
ECHO Welcome to the startup of your new Minecraft server^^!
ECHO Upon completion of the first start, please exit the program and run "start.bat".
ECHO When you are ready, press any key.
PAUSE>NUL
SET /p "hasrun" = < "%~dp0\hasrun.txt"
:Run
IF "!hasrun!" == "0" (
ECHO "1" >> "%~dp0\hasrun.txt"
java -Xms1024M -Xmx1024M -jar minecraft_server.jar nogui
) ELSE (
ECHO This is not your first run^^! Use "start.bat" instead^^!
PAUSE
)
错误似乎发生在ECHO "1" >> "%~dp0\hasrun.txt" 所在的行。自从我上次批量写任何东西以来已经有一段时间了,所以这很可能是显而易见的。确切的输出(回声关闭)是:
Welcome to the startup of your new Minecraft server!
Upon completion of the first start, please exit the program and run "start.bat".
When you are ready, press any key.
按一个键传递PAUSE后,它会说:
The syntax of the command is incorrect.
This is not your first run! Use "start.bat" instead!
Press any key to continue...
另外,hasrun.txt 的内容只是一个零。 (“0”不带引号)
【问题讨论】:
-
我回滚了您的编辑。一旦你开始收到答案,你就不能继续向同一个问题添加新问题。如果您现在有一个新问题,这是一个新问题,您需要将其作为一个问题发布。您可以随时在新问题中提供此问题的链接以供参考。
-
!hasrun!的内容是在这之前设置的吗?如果是这样,请从我的答案中否定if not exist...行,并将"!hasrun!"=="0 "替换为"!hasrun!"=="0"。
标签: windows batch-file windows-7 syntax-error