@echo off
color c
set 1=direwolf15
set 2=direwolf16
set 3=magicworld1
set 4=magicworld2
set 5=magicfarm
set 6=magicfarm2
set 7=ftblite1
set 8=ftblite2
set 9=horizons
set 10=monster
set 11=unleashed
set 12=techworld1
set 13=techworld2
echo "--------------------------------"
echo "| Universal server starter |"
echo "--------------------------------"
echo.
echo ==================================
echo 1. Direwolf 1.5
echo 2. Direwolf 1.6
echo 3. Magic Word l
echo 4. Magic Word 2
echo 5. Magic Farm 1
echo 6. Magic Farm 2
echo 7. FTB Lite 1
echo 8. FTB Lite 2
echo 9. Horizons
echo 10. Monster
echo 11. Unleashed
echo 12. Tech World 1
echo 13. Tech World 2
echo ===================================
echo.
set /p "whattostart=Enter the number of the server to start: "%=%
if "%whattostart%" == "1" (start /min \direwolf1.5\startserver.bat ^& exit)
IF NOT EXIST \direwolf1.5\ (echo that server does not exist)
if "%whattostart%" == "2" (start /min \direwolf1.6\startserver.bat ^& exit)
IF NOT EXIST \direwolf1.6 (echo that server does not exist)
if "%whattostart%" == "3" (start /min \magicworld1\startserver.bat ^& exit)
IF NOT EXIST \magicworld1 (echo that server does not exist)
if "%whattostart%" == "4" (start /min \magicworld2\startserver.bat ^& exit)
IF NOT EXIST \magicworld2 (echo that server does not exist)
if "%whattostart%" == "5" (start /min \magicfarm1\startserver.bat ^& exit)
IF NOT EXIST \magicfarm1 (echo that server does not exist)
if "%whattostart%" == "6" (start /min \magicfarm2\startserver.bat ^& exit)
IF NOT EXIST \magicfarm2 (echo that server does not exist)
if "%whattostart%" == "7" (start /min \ftblite1\startserver.bat ^& exit)
IF NOT EXIST \ftblite1 (echo that server does not exist)
if "%whattostart%" == "8" (start /min \ftblite2\startserver.bat ^& exit)
IF NOT EXIST \ftblite2 (echo that server does not exist)
if "%whattostart%" == "9" (start /min \horizons\startserver.bat ^& exit)
IF NOT EXIST \horizons (echo that server does not exist)
if "%whattostart%" == "10" (start /min \monster\startserver.bat ^& exit)
IF NOT EXIST \monster (echo that server does not exist)
if "%whattostart%" == "11" (start /min \unleashed\startserver.bat ^& exit)
IF NOT EXIST \unleashed (echo that server does not exist)
if "%whattostart%" == "12" (start /min \techworld1\startserver.bat ^& exit)
IF NOT EXIST \techworld1 (echo that server does not exist)
if "%whattostart%" == "13" (start /min \techworld2\startserver.bat ^& exit)
IF NOT EXIST \techworld2 (echo that server does not exist)
pause
exit
每次我尝试运行它时都说服务器不存在,即使我有文件夹和批处理文件。我不知道如何解决它,我是批量编程的初学者,所以一些帮助将非常感激。谢谢你的时间!
编辑:现在使用固定代码,它找不到文件 这是它的图片: http://i.stack.imgur.com/QCY3F.png
答案 0 :(得分:0)
要访问变量内的值,您需要使用
if %whattostart%=="1" ....
但是,如果你看一下上面一行,比较是在一个带引号的字符串("1"
)和变量的值之间,不会被引用(当然,除非用户输入引号) 。所以,该行应该是
if "%whattostart%"=="1" ....
而且,为了最大限度地减少用户输入的问题,您的set /p
行应
set /p "whattostart=Enter the number of the server to start: "