我有了用戶輸入一個批處理腳本:批「if」語句,只會如果輸入的文本做一些事情,否則去做些別的事情
set /p serverstart=Starter Path (or leave blank if unknown):
現在需要採取什麼措施是,如果一個用戶輸入一些東西(任何東西)它會去特定的標籤:
if %serverstart% == [anything] goto %serverstart%
:%serverstart%
java -Xmx1024M -Xms1024M -jar %serverstart%.jar nogui
但只有當用戶輸入的東西。如果用戶離開該領域的空白,該文件需要繼續它的方式:
set /p serverstart=Starter Path (or leave blank if unknown):
:serverram
cls
set /p serverram=Server RAM:
[enter more code here]
因此,如果用戶輸入什麼它進入用戶定義的標籤,並啓動%serverstart%的.jar,但如果用戶將該字段留空,它什麼都不做,繼續進行。會:
set /p serverstart=Starter Path (or leave blank if unknown):
if %serverstart% == "" goto %serverstart%
goto serverram
:serverram
set /p serverram=Server RAM:
:%serverstart%
java -Xmx%serverram%M -Xms%serverram%M -jar %serverstart%.jar nogui
工作?
(只是櫃面你想要的話,這裏是完整的代碼到目前爲止)
@ECHO OFF
title MineServer Runner
cls
:servername
cls
if exist ServerFiles\serverconfig.cmd goto startserver
set /p servername=Server Name:
echo set servername=%servername%>> ServerFiles\serverconfig.cmd
call "ServerFiles\serverconfig.cmd"
title MineServer (%servername%) Runner
set /p serverstart=Starter Path (or leave blank if unknown):
:serverram
cls
set /p serverram=Server RAM:
echo set serverram=%serverram%>> ServerFiles\serverconfig.cmd
:startserver
cd ServerFiles
call "serverconfig.cmd"
java -Xmx%serverram%M -Xms%serverram%M -jar starters\minecraft_server.jar nogui
@Stephan:就像你說的那樣,很好的捕捉! – Magoo 2014-11-08 09:47:27