Page 1 of 1

Is it possible to pipe an output to a for loop?

Posted: 01 Aug 2010 17:40
by orange_batch
Hi guys, new here. 8)

For example, I have this here:

dir >dir.txt
for /f "tokens=5" %%a in (dir.txt) do @echo %%a


...but I'd like to do this if I can:

dir | for /f "tokens=5" %%a in (output of dir) do @echo %%a


Thanks for your help.

Re: Is it possible to pipe an output to a for loop?

Posted: 01 Aug 2010 17:54
by aGerman
You can process a command into a for loop. Use apostrophes into the brackets.

Code: Select all

for /f "delims=" %%a in ('dir /b') do echo %%a

Option /b means that only the filenames are outputed, no header.

Regards
aGerman

Re: Is it possible to pipe an output to a for loop?

Posted: 02 Aug 2010 09:52
by orange_batch
Ahh, thanks again. I'm very rusty. :roll:

Re: Is it possible to pipe an output to a for loop?

Posted: 07 Aug 2010 12:21
by luca
echo off
set a1=1
set b1=2
set c1=1
for %%x in (%a1%,%b1%,%c1%) do echo %%x > pippo.txt| set /a x=%%x+1 :)

Re: Is it possible to pipe an output to a for loop?

Posted: 09 Aug 2010 12:22
by luca
rem example pipe
echo off
:10
set /a a1=%random:~1,1%
set /a b1=%random:~1,1%
set /a c1=%random:~1,1%
set /a d1=%random:~1,1%
for %%x in (%a1%,%b1%,%c1%,%d1%) do for %%y in (%a1%,%b1%,%c1%,%d1%) do echo %%z > pippo.txt| set /a z=%%x*%%y
goto 10