Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This could also be read "Why can't I get the for command work in my batch file."

When I try using the command:

FOR /F "tokens=1-4 delims=/ " %%a in ('something cool') DO something else cool %%a %%b %%c

It doesn't work! I'm getting:

%%a was unexpected at this time

share|improve this question

closed as off topic by Ignacio Vazquez-Abrams, Zoredache, Ward, John Gardeniers, mdpc Nov 2 '12 at 16:14

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

I'm mainly asking this because I've been asked this several times. – Nixphoe Aug 8 '11 at 1:12
up vote 4 down vote accepted

The reason for this is that you need a single % when you're doing this in the command prompt and a double %% when you're doing it from a batch file.

Example Command Line:

FOR /F "tokens=1-4 delims=/ " %a in ('something cool') DO something else cool %a %b %c

Example Batch File:

FOR /F "tokens=1-4 delims=/ " %%a in ('something cool') DO something else cool %%a %%b %%c
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.