【发布时间】:2011-11-22 21:12:14
【问题描述】:
我在处理需要将配置文件中的值解析为变量的批处理脚本时遇到了一些问题。
适当匿名,文件的相关行看起来像
<?define ProductShortName="Foo" ?>
我想将变量设置为Foo。字符串ProductShortName 足够独特,可以得到findstr 的行,但是我必须提取值。正确的方法似乎是for /F,但以下所有错误:
for /F "delims=^" usebackq" %%G in (`findstr /L "ProductShortName" "%~dp0Installer\Branding.wxi"`)
for /F "delims="" usebackq" %%G in (`findstr /L "ProductShortName" "%~dp0Installer\Branding.wxi"`)
for /F "delims=\" usebackq" %%G in (`findstr /L "ProductShortName" "%~dp0Installer\Branding.wxi"`)
for /F 'delims=^" usebackq' %%G in (`findstr /L "ProductShortName" "%~dp0Installer\Branding.wxi"`)
for /F 'delims=" usebackq' %%G in (`findstr /L "ProductShortName" "%~dp0Installer\Branding.wxi"`)
for /F "delims=" usebackq" %%G in (`findstr /L "ProductShortName" "%~dp0Installer\Branding.wxi"`)
基本上是这样的
usebackq" %G in (`findstr /L "ProductShortName" "C:\foo\bar\Installer\Branding.wxi"`) was unexpected at this time.
转义它以拆分"上的字符串的正确方法是什么?
【问题讨论】:
-
幽默一下,试试这个:
for /F "USEBACKQ tokens=3 delims= =" %%G in (findstr /L ProductShortName "%~dp0Installer\Branding.wxi"`) DO (SET var=%%~G)
标签: batch-file escaping