2015-04-05 67 views
-2

我为我的Minecraft服务器制作了一个自定义启动脚本,所以我可以使用更多的RAM。 当您停止服务器时,它会询问您是要重新启动还是要停止。 如果在20秒后没有应答,我无法自动重新启动(在发生崩溃的情况下) 。请帮忙。20秒后自动进行选择

@echo off 
title minecraft-server-1.8.3 
color 0A 
prompt [server]: 
cls 

:start           //starts the server 
echo loading server... 
java -Xms3G -Xmx3G -jar minecraft_server.1.8.3.jar nogui 
cls 

[code to restart the server when it didn't get an anwser in 20sec] 

:choice           //what to do when 
set /P a=do you want to restart[Y/N]?    the server stops 
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 

回答

2

代替set /p使用choice

choice /c YN /t 20 /d Y /m "Do you want to restart " 
  • /c YN状态回答集(Y或N,情况下,由方式不敏感的)。
  • /t 20表示超时20秒。
  • /d Y表示超时到期后的默认答案Y.
  • /m "..."陈述提示。

choiceerrorlevel到输入(Y:1,N:2)的索引,以便查询的用户输入的使用:

if %errorlevel% equ 1 goto :restart 
if %errorlevel% equ 2 goto :stop 

可以在http://ss64.com/nt/choice.html或类型找到更多有关choicechoice/?

+0

应该指出的是,这个命令在Windows XP上不存在,但IMO仍然使用XP的唯一原因是工作。 – SomethingDark 2015-04-06 06:41:06