windows 使用批处理脚本读取属性文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7687466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:13:22  来源:igfitidea点击:

Using batch script to read properties file

windowsbatch-file

提问by AabinGunz

I have a properties file located %ilmhome%\webapp\WEB-INF\amhome.properties

我有一个属性文件位于 %ilmhome%\webapp\WEB-INF\amhome.properties

#Tue Feb 15 19:27:14 IST 2011
amhome.connection.password=amhome534
amhome.connection.url=jdbc\:oracle\:thin\:@(DESCRIPTION\=(ADDRESS_LIST\=(ADDRESS\=(PROTOCOL\=TCP)(HOST\=diablo)(PORT\=1521)))(CONNECT_DATA\=(SERVER\=DEDICATED)(SERVICE_NAME\=orcl)))
amhome.connection.maxWait=20000
amhome.connection.username=amhome534
amhome.connection.platformId=6
amhome.connection.driver_class=oracle.jdbc.driver.OracleDriver

I want to fetch the below items from amhome.properties file into some variables

我想从 amhome.properties 文件中获取以下项目到一些变量中

Username        : amhome534
Host            : diablo
Port            : 1521
ServiceName    : orcl
ConnString     : jdbc\:oracle\:thin\:@(DESCRIPTION\=(ADDRESS_LIST\=(ADDRESS\=(PROTOCOL\=TCP)(HOST\=diablo)(PORT\=1521)))(CONNECT_DATA\=(SERVER\=DEDICATED)(SERVICE_NAME\=orcl)))

How can i do that?

我怎样才能做到这一点?

采纳答案by ewall

Check out the FOR /F command... You should be able to set DELIMS=.=and TOKENS=3,*which would skip 'amhome' and 'connection' but give you value pairs like 'password' + 'amhome534'.

退房FOR / F命令......你应该能够设置DELIMS=.=TOKENS=3,*其将跳过“amhome”和“连接”,但给你值对像“密码” +“amhome534”。