I'm having a bit of trouble with a batch script which needs to parse a value out of an config file into a variable.
Suitably anonymised, the relevant line of the file looks like
<?define ProductShortName="Foo" ?>
I want to set a variable to Foo
. The string ProductShortName
is unique enough to get the line with findstr
, but then I have to extract the value. The correct approach seems to be for /F
, but all of the following give errors:
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"`)
mostly along the lines of
usebackq" %G in (`findstr /L "ProductShortName" "C:\foo\bar\Installer\Branding.wxi"`) was unexpected at this time.
What's the correct way of escaping it to split the string on "
?
for /F "USEBACKQ tokens=3 delims= =" %%G in (
findstr /L ProductShortName "%~dp0Installer\Branding.wxi"`) DO (SET var=%%~G) – Dilworth