我的.bat文件如下所示:
setlocal enableextensions enabledelayedexpansion
setlocal enabledelayedexpansion
for /f "tokens=2 delims=:" %%a in ('ipconfig^|find "IPv4 Address"') do (
set ip=%%a
goto :BREAK
)
:BREAK
echo %ip: =% >ip.txt
goto :Loopforcheck
:Loopforcheck
goto :Copy
if exist <ip.txt> (
goto :Copy
) else (
echo failed to find file
goto :Loopforcheck
)
:Copy
for /F "delims=" %%i in (ip.txt) do (
set "D=server-ip=%%i"
echo max-tick-time=60000> server.properties
echo server-name=Unknown Server>> server.properties
echo generator-settings=>> server.properties
echo force-gamemode=false>> server.properties
echo allow-nether=true>> server.properties
echo gamemode=0 >> server.properties
echo enable-query=false>> server.properties
echo player-idle-timeout=0>> server.properties
echo difficulty=1>> server.properties
echo spawn-monsters=true>> server.properties
echo op-permission-level=4>> server.properties
echo announce-player-achievements=true >> server.properties
echo pvp=true >> server.properties
echo snooper-enabled=true>> server.properties
echo level-type=DEFAULT>> server.properties
echo hardcore=false>> server.properties
echo enable-command-block=true >> server.properties
echo max-players=20>> server.properties
echo network-compression-threshold=256 >> server.properties
echo resource-pack-sha1=>> server.properties
echo max-world-size=29999984>> server.properties
echo server-port=1>> server.properties
echo !D!>>server.properties
echo spawn-npcs=true>> server.properties
echo allow-flight=false>> server.properties
echo level-name=world>> server.properties
echo view-distance=10>> server.properties
echo resource-pack=>> server.properties
echo spawn-animals=true>> server.properties
echo white-list=false>> server.properties
echo generate-structures=true>> server.properties
echo online-mode=false>> server.properties
echo max-build-height=256>> server.properties
echo level-seed=assboobs>> server.properties
echo enable-rcon=false>> server.properties
echo motd=MINECRAFT BG>> server.properties
)
)
goto :Exit
:Exit
TIMEOUT 3
Del ip.txt
java -Xmx3G -Xms3G -jar m.jar -o false
PAUSE
del server.properties
我的输出server.properties就像这样
max-tick-time=60000
server-name=Unknown Server
generator-settings=
force-gamemode=false
allow-nether=true
gamemode=0
enable-query=false
difficulty=
spawn-monsters=true
announce-player-achievements=true
pvp=true
snooper-enabled=true
level-type=DEFAULT
hardcore=false
enable-command-block=true
max-players=20
network-compression-threshold=256
resource-pack-sha1=
max-world-size=29999984
server-port=
server-ip=192.168.2.100 <------ THERE IS A SPACE!
spawn-npcs=true
allow-flight=false
level-name=world
view-distance=10
resource-pack=
spawn-animals=true
white-list=false
generate-structures=true
online-mode=false
max-build-height=256
level-seed=assboobs
enable-rcon=false
motd=MINECRAFT BG
我想删除这个空间! 当我运行我的m.jar文件时,我得到了这个错误 遇到意外的异常java.net.UnknownHostException: 192.168.2.100
答案 0 :(得分:2)
echo %ip: =%
删除所有空格,但echo %variable% >ip.txt
会插入一个新空格。注意:在重定向之前删除空间可以解决问题,但可能会让您遇到数字问题。替代更好的语法:
(echo %%ip: =%)>ip.txt
或
>ip.txt echo %ip: =%