我想在属性中设置名称值对的变量.属性文件有#作为注释
====示例输入文件=====
#This is a comment
### Another comment
appNames=HelloWorldApp
targetServer=serverABC
DEV.key1=value1
TEST.key2=value2
Run Code Online (Sandbox Code Playgroud)
=========我有2个问题
1)
C:\temp\dos>for /f "delims=" %i in (test.properties) do @set %i
Environment variable #This is a not defined
Environment variable ### Another not defined
Run Code Online (Sandbox Code Playgroud)
变量已设置,但我希望忽略注释.我想用一行代码执行此操作,但请改为使用.
for /f "delims=" %i in (test.properties) do @echo %i | find "#">nul || @set %i
find: unable to access "#": The system cannot find the file specified.
The process tried to write to a nonexistent pipe.
Environment variable #This is a not defined
find: unable to access "#": The system cannot find the file specified.
The process tried to write to a nonexistent pipe.
Run Code Online (Sandbox Code Playgroud)
2)我希望将此属性文件作为参数传递给批处理脚本.test.bat文件的内容
set propFilePathAndName=%1
for /f "delims=" %i in (%propFilePathAndName%) do echo %i
Run Code Online (Sandbox Code Playgroud)
产量
C:\temp\dos>set propFilePathAndName=/temp/dos/test.properties
propFilePathAndNamei was unexpected at this time.
Run Code Online (Sandbox Code Playgroud)
如果我一次运行一行这个文件的内容,它就可以了.我究竟做错了什么?提前致谢
要忽略以哈希开头的行,可以使用eolfor循环的参数.
for /f "eol=# delims=" %i in (test.properties) do @set %i
第二个问题是将批处理文件内的百分比加倍.
set propFilePathAndName=%1
for /f "delims=" %%i in (%propFilePathAndName%) do echo %%i
Run Code Online (Sandbox Code Playgroud)
这是由解析器引起的,命令行和批处理文件有不同的规则.
CMD线
for %a in (xyz) do echo %a
批处理文件
for %%a in (xyz) do echo %%a