我正在编写一个批处理,以便在众多设备上自动安装许多设置,INI文件和APK。由于显示 NULL 的变量,我在批处理中遇到错误。
我已检查 config.ini 和 ADBCommands.ini 以及 adb + .bat 位于正确的位置。
你能帮忙吗?
::Global
@echo off
cd C:\
::INI Locations
set mypath=%~dp0
set config=%mypath%config.ini
set Commands=%mypath%ADBCommands.ini
set multi=%mypath%adb+.bat
@pause
::Set Varialbes
@for /f "tokens=1,2 delims==" %%a in (%config%) do (
if %%a==Build set Build=%%b
if %%a==Version set Version=%%b
if %%a==Creator set Creator=%%b
if %%a==DateModified set DateModified=%%b
if %%a==ScreenTimeout set ScreenTimeout=%%b
if %%a==UnknownSources set UnknownSources=%%b
if %%a==ScreenBrightness set ScreenBrightness=%%b
)
@for /f "tokens=1,2 delims==" %%d in (%Commands%) do (
if %%d==ScreenTimeoutCommand set ScreenTimeoutCommand=%%e
if %%d==UnknownSourcesCommand set UnknownSourcesCommand=%%e
if %%d==ScreenBrightnessCommand set ScreenBrightnessCommand=%%e
if %%d==OpenSOTICommand set OpenSOTICommand=%%e
)
::Build information
cls
@echo.
@echo.
@echo BUILD: %Build%
@echo VERSION: %Version%
@echo BUILD CREATOR: %Creator%
@echo LAST UPDATED: %DateModified%
@echo.
@echo.
@pause
列出ini文件 的的config.ini
Build=XCover 3
Version=1.0.0
Creator=James B
DateModified=20/02/2017
ScreenTimeout=300000
UnknownSources=1
ScreenBrightness=225
列出ini文件 的 ADBCommands.ini
ScreenTimeoutCommand=shell settings put system screen_off_timeout
UnknownSourcesCommand=shell settings put system install_non_market_apps
OpenSOTICommand=shell am start -n net.soti.mobicontrol.elm.samsung/net.soti.mobicontrol.startup.SplashActivity
答案 0 :(得分:1)
因为您的路径有空格,所以需要用引号将路径括起来。但是当你这样做时,你需要告诉FOR / F命令你仍在解析文件而不是变量。所以你需要使用USEBACKQ选项。
@for /f "usebackq tokens=1,2 delims==" %%a in ("%config%") do (
和
@for /f "usebackq tokens=1,2 delims==" %%d in ("%Commands%") do (