windows 需要为我的世界服务器批量自动重启脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26250361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Need auto-restart script in batch for minecraft server
提问by Collin Vee
I am currently an administrator on a private Minecraft server, though in this case the technical question lies outside the scope of typical minecraft supoort.
我目前是私人 Minecraft 服务器的管理员,但在这种情况下,技术问题超出了典型的 Minecraft 支持范围。
I wish to have the batch file that launches the server restart at 12 am and 12 pm, though I have little experience in batch and a cursory google search brings up nothing helpful.
我希望启动服务器的批处理文件在上午 12 点和下午 12 点重新启动,尽管我在批处理方面的经验很少,粗略的谷歌搜索没有任何帮助。
The issue I run into is both that I have no idea if batch CAN execute commands within a java server console, send the commands to save the server and then exit, and restart itself, due to only knowing basic batch functions.
我遇到的问题是,由于只知道基本的批处理功能,我不知道批处理 CAN 是否在 Java 服务器控制台中执行命令,发送命令以保存服务器然后退出,然后重新启动自身。
More specifically, I want the batch file itself to run a command in the server window after either 43200 seconds or on each of the 12s, then restart itself. I do not know how to get a batch file to run a command within the server command line, or if it's even possible.
更具体地说,我希望批处理文件本身在 43200 秒后或每 12 秒后在服务器窗口中运行命令,然后重新启动。我不知道如何获取批处理文件以在服务器命令行中运行命令,或者是否可能。
The current batch code is as follows:
当前批次代码如下:
@echo off
:Minecraft
echo (%time%) Minecraft started.
java -Xms2048m -Xmx2048m -XX:PermSize=128m -jar FTBServer-1.6.4-965.jar nogui
pause
echo (%time%) WARNING: Minecraft closed or crashed, restarting.
ping 1.1.1.1 -n 1 -w 3000 >nul
goto Minecraft
Any help would be aprreciated. Thanks.
任何帮助将不胜感激。谢谢。
回答by fanta fles
i use this but if you want it to restart it automatically then just delete the :choise part and make a loop from start to restart
我使用它,但如果您希望它自动重新启动它,那么只需删除 :choise 部分并从开始到重新启动循环
@echo off
title minecraft-server-1.8.3
color 0A
prompt [server]:
cls
:start
echo loading server...
java -Xms3G -Xmx3G -jar minecraft_server.1.8.3.jar nogui
cls
:choice
set /P a=do you want to restart[Y/N]?
if /I "%a%" EQU "Y" goto :restart
if /I "%a%" EQU "N" goto :stop
goto :choice
:restart
cls
echo server will restart
TIMEOUT /T 5
cls
goto :start
:stop
cls
echo closing server
TIMEOUT /T 5
exit
ps. replace minecraft_server.1.8.3.jar with the name of your server file
附:用你的服务器文件名替换 minecraft_server.1.8.3.jar
回答by MichaelS
Solution 1: I would suggest to use the windows task scheduler instead of a batch file. There you can create a task, schedule it to be triggered at 12am/pm and insert any cmd command you want to be executed. However, it's non-trivial to cummunicate with the server console without knowing the specific interface or how to administrate a minecraft server. What you can do is simply kill the server and restart it using the command line.
解决方案 1:我建议使用 Windows 任务调度程序而不是批处理文件。在那里你可以创建一个任务,安排它在中午 12 点/下午触发,并插入你想要执行的任何 cmd 命令。但是,在不知道特定界面或如何管理 minecraft 服务器的情况下,与服务器控制台进行通信是很重要的。您可以做的只是终止服务器并使用命令行重新启动它。
Solution 2: If you don't like this solution and don't know how to communicate with the server console you can try this: Take a look at AutoIt (https://www.autoitscript.com/site/). It's a VERY simple script language which also can simulate click and input from the keyboard. So you can write a script that sets the focus to your server console and types the desired command to restart the server. This AutoIt script can be compiled to an exe file or you can run it as an au3 script. You should still use the task scheduler to run your exe/script at 12am/pm.
解决方案 2:如果您不喜欢此解决方案并且不知道如何与服务器控制台通信,您可以尝试以下方法:查看 AutoIt ( https://www.autoitscript.com/site/)。它是一种非常简单的脚本语言,它也可以模拟键盘的点击和输入。因此,您可以编写一个脚本,将焦点设置到您的服务器控制台并键入所需的命令来重新启动服务器。该 AutoIt 脚本可以编译为 exe 文件,也可以将其作为 au3 脚本运行。您仍然应该使用任务调度程序在中午 12 点/下午运行您的 exe/脚本。
If you need some help writing the AutoIt script I can help you with that.
如果您在编写 AutoIt 脚本时需要帮助,我可以为您提供帮助。
回答by CptVince
I wrote a similar program for a friend in AutoIt here is the script i commented the lines you need to config:
我在 AutoIt 中为朋友写了一个类似的程序,这里是我注释了您需要配置的行的脚本:
HotKeySet("{ESC}", end)
HotKeySet("{F1}", start) ;optional
HotKeySet("{F2}", pause) ;optional
pause() ; starts the pause loop when started
; restarts the server all 12 hours
Func start()
$Path = "PathToYourBatch.bat" ; self explained
While 1
If @HOUR = 00 Or @HOUR = 12 Then ;starts the server at 00 and 12
Run($Path)
EndIf
WEnd
EndFunc
Func pause()
While 1
Sleep(500) ; waits 500 ms to reduce lag
WEnd
EndFunc
Func end()
Exit
EndFunc
You dont need to use the hotkeys but you could easily control the program with them(remote desktop)
您不需要使用热键,但您可以使用它们轻松控制程序(远程桌面)
You can use a online compiler like (http://www.script-example.com/themen/AutoIT-Online-Compiler.php) or download it from (https://www.autoitscript.com/site/) hope i could help if any further questions with the code ask me.
您可以使用在线编译器(http://www.script-example.com/themen/AutoIT-Online-Compiler.php)或从(https://www.autoitscript.com/site/)下载,希望我如果有关代码的任何其他问题问我,可能会有所帮助。