[批处理]获取设备IP,调用其他批处理,更新文件内容
调用其他批处理
@echo off rem 使用XXXX运行目录路径 set propath=E:\workspace\XXXX rem 调用XXXX call %propath%\Data\Project\XXXXip.bat pause
获取IP
@echo off echo 配置 setlocal ENABLEEXTENSIONS & set "i=0.0.0.0" & set "j=" for /f "tokens=4" %%a in ('route print^|findstr 0.0.0.0.*0.0.0.0') do ( if not defined j for %%b in (%%a) do set "i=%%b" & set "j=1") endlocal & set "ip=%i%" echo IP 地址是:%ip%
修改文件
set cfg=%propath%\Bin\Release\XXX.cfg set cfgtemp=%propath%\Bin\Release\temp_XXX.cfg if exist %cfg% goto dchange echo %cfg%未找到 goto :end :dchange echo %cfg%已经找到 setlocal enabledelayedexpansion for /f "tokens=*" %%i in (%cfg%) do ( set lines=%%i echo %%i|find /i "tcpServerIP">nul&&(set lines=tcpServerIP=%ip%)||(echo %%i|find /i "ServerIP">nul&&(set lines=ServerIP=%ip%)) echo !lines!>>%cfgtemp% ) move %cfgtemp% %cfg% :end