0

I have a java properties file to parse, it contains key value pairs of the form key=value, one on each line. After digging around on the site, I've found this site that explains the FOR syntax, and also this question.

I constructed the following line to get the value of the backupdir.windows property in config.properties:

for /f "delims== tokens=2" %i in ('findstr backupdir.windows= config.properties') do  @echo %i

The above works if you type it at the command prompt, but if I save it as a file 'test.cmd' and then execute that, I get 'i was unexpected at this time.' Same thing happens if I change the extension to .bat (in case doing so would make it use earlier MSDOS syntax).

What's going wrong here? I'm running Windows 7.

Community
  • 1
  • 1
Rex
  • 801
  • 1
  • 17
  • 26
  • 3
    Simply double the percent signs from `%i` to `%%i` inside of a batch file – jeb Oct 31 '11 at 12:29
  • @jeb If you write that in as an answer instead of a comment, then Rex could give you credit for it. – ewall Nov 15 '11 at 21:48

2 Answers2

2

Better to do it like this:

@echo off
for /f "tokens=2 delims==" %%a in ('findstr /b /i "backupdir.windows" config.properties') do echo %%a
Paul Tomasi
  • 655
  • 3
  • 9
1

it needs to be %%i in a batch file. And just %i on the command line.

Paul Tomasi
  • 655
  • 3
  • 9