Looking at the documentation for
for /? to see it), I don't think
for /f will read from a pipe. The only valid sources are file-set, "string", and 'command'.
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
You could put the command inside the
for like this:
for /f "tokens=15" %f in ('ipconfig ^| findstr "Address"') do @echo %f
(thanks to neurolysis for pointing out it has to be
^| and not just
Or you could try putting
ipconfig | findstr "Address" in a separate batch script and calling:
for /f "tokens=14" %f in ('ipaddresses') do @echo %f
(assuming you called the script
Or you could use
for to do the work of
findstr too, like this:
for /f "tokens=2,14" %i in ('ipconfig') do @if %i==Address. @echo %j
it's not quite the same because it won't match IPv6 addresses, but something along those lines could work.
Also note that I changed
tokens=14. I think the last field on the line is token 14. Works for me anyway.