2015-04-05 70 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