bat读配置文件*.properties
2015-11-25 14:14
295 查看
原文地址:http://michael-paul.iteye.com/blog/740000
i want to read a below property file and get the particular key value
My properties file look like
I want get the version from the properties file. you can do this by various method.
Using Type function:
C:\Users\Arul\Desktop>type test.properties | find “version”
There is disadvantage with this method you could not store that value in a variable.
Using For Loop:
C:\Users\Arul\Desktop>FOR /F %i IN (test.properties) DO echo %i
using this command you can read that file by line by line.
FOR /F “eol=; tokens=2,2 delims==” %i IN (test.properties) DO echo %i
Using this commend you can get the values only.
eol is End of Line
tokens is specify the which tokens are displayed – 2,2 means only the second token will be displayed
delims is the deliminator . this is the separator
Using findstr get the correct string from the properties file and give as a input to the for loop. That for loop process the result and set that value to the variable version.
findstr /i means is not a case sensitive one
using echo you can get the value.
echo %version%
When you using in a bat add a % befor %i. That is Look like
i want to read a below property file and get the particular key value
My properties file look like
name=arulraj.net version=1.0.2 date=24/March/2010
I want get the version from the properties file. you can do this by various method.
Using Type function:
C:\Users\Arul\Desktop>type test.properties | find “version”
There is disadvantage with this method you could not store that value in a variable.
Using For Loop:
C:\Users\Arul\Desktop>FOR /F %i IN (test.properties) DO echo %i
using this command you can read that file by line by line.
FOR /F “eol=; tokens=2,2 delims==” %i IN (test.properties) DO echo %i
Using this commend you can get the values only.
eol is End of Line
tokens is specify the which tokens are displayed – 2,2 means only the second token will be displayed
delims is the deliminator . this is the separator
FOR /F "eol=; tokens=2,2 delims==" %i IN ('findstr /i "version" test.properties') DO set version=%i
Using findstr get the correct string from the properties file and give as a input to the for loop. That for loop process the result and set that value to the variable version.
findstr /i means is not a case sensitive one
using echo you can get the value.
echo %version%
When you using in a bat add a % befor %i. That is Look like
FOR /F "eol=; tokens=2,2 delims==" %%i IN ('findstr /i "version" test.properties') DO set version=%%i echo %version%
相关文章推荐
- 让Python文件也可以当bat文件运行
- Oracle Containers for J2EE远程安全漏洞(CVE-2014-0413)
- C位出道后却遇前狼后虎,生鲜电商多点如何突围?
- “to B”的金矿还是BAT的?
- Bat:一种具有语法高亮和 Git 集成的 Cat 类命令
- bat 截取字符串(for命令) 推荐收藏
- 实现FTP整站上传的批处理代码
- 杀毒软件 Dr.Web Anti-virus for Windows Vista 4.44.0 Beta
- 批处理向FTP上传具有指定属性的文件(增量备份)
- C#中循环语句:while、for、foreach的使用
- vbs与bat混编修改虚拟盘符的卷标
- 使用BAT批处理执行sql语句的代码
- BAT 参数去引号(各种去引号的奇葩方式)
- for 提取文本整行内容的方法
- bat 文件 学习使用指南
- BAT批处理实现字符串截取功能
- 批处理bat 延时执行命令的两种方法
- 可以生成SLEEP.EXE的延时命令的bat文件
- dos命令for用法详解
- 执行批处理bat程序中的条件处理