@echo off
SETLOCAL
For /F "tokens=1* delims==" %%A IN (build.properties) DO (
IF "%%A"=="projectPath" set lprojectPath=%%B
IF "%%A"=="warSourcePath" set lwarSourcePath=%%B
IF "%%A"=="warDestinationPath" set lwarDestinationPath=%%B
IF "%%A"=="serverPath" set lserverPath=%%B
)
echo "%lprojectPath%"
echo "%lwarSourcePath%"
echo "%lwarDestinationPath%"
echo "%lserverPath%"
I have a properties file named build.properties(key=value). when I run the above bat file echo prints "" an empty string in cmd and I am not able to use the variable values else where in the bat file. I am I making any mistake in retrieval of values from properties file.
我有一个名为build.properties(key = value)的属性文件。当我运行上面的bat文件时,echo会在cmd中打印一个空字符串,而我无法在bat文件中使用其他位置的变量值。我在从属性文件中检索值时犯了任何错误。
projectPath = D:\DEV_R4.6_bat_test\brsint-web\brisnt-scheduling
warSourcePath = D:\DEV_R4.6_bat_test\brsint-web\brsint-webapp\target\Bristow.war
warDestinationPath = D:\apache-tomcat-7.0_1.2Latest (2)\webapps
serverPath = D:\apache-tomcat-7.0_1.2Latest (2)\bin
This is my properties file.
这是我的属性文件。
2 个解决方案
#1
1
In a similar setup for a name=value
.ini I use,
在我使用的name = value .ini的类似设置中,
FOR /f %%a IN (db.ini) DO SET %%a
%%a
expands after the SET
command as name=value
, thus creating the variable. eg; SET name=value
%% a在SET命令之后作为name = value扩展,从而创建变量。例如; SET name = value
If the "l" character is essential write the line with the "l" preceding the parameter:
如果必需“l”字符,请在参数前面加上“l”的行:
FOR /f %%a IN (build.properties) DO SET l%%a
#2
0
uh - there are spaces in your build.properties
. Spaces are critical with the set
command. Use:
呃 - 你的build.properties中有空格。空间对set命令至关重要。使用:
@echo off
setlocal
for /f "tokens=1,* delims== " %%a in (build.properties) do set "l%%a=%%b"
REM note the space in delims
set l
Your original code defines variables like %projectPath %
(note the space) with contents like <SPACE>D:\DEV_R4.6_bat_test\brsint-web\brisnt-scheduling
您的原始代码使用像
#1
1
In a similar setup for a name=value
.ini I use,
在我使用的name = value .ini的类似设置中,
FOR /f %%a IN (db.ini) DO SET %%a
%%a
expands after the SET
command as name=value
, thus creating the variable. eg; SET name=value
%% a在SET命令之后作为name = value扩展,从而创建变量。例如; SET name = value
If the "l" character is essential write the line with the "l" preceding the parameter:
如果必需“l”字符,请在参数前面加上“l”的行:
FOR /f %%a IN (build.properties) DO SET l%%a
#2
0
uh - there are spaces in your build.properties
. Spaces are critical with the set
command. Use:
呃 - 你的build.properties中有空格。空间对set命令至关重要。使用:
@echo off
setlocal
for /f "tokens=1,* delims== " %%a in (build.properties) do set "l%%a=%%b"
REM note the space in delims
set l
Your original code defines variables like %projectPath %
(note the space) with contents like <SPACE>D:\DEV_R4.6_bat_test\brsint-web\brisnt-scheduling
您的原始代码使用像