I was wondering if it is possible to read from a pipe in a batch file. If I write:
echo Test
i get, unsurprising, Test
. That's nice. But what if I want to pipe the output, and read it from another command?
echo Test | echo ???
How to obtain the same result as before, but through a pipe? Thanks!
EDIT: what I am after really after is this.
I have a list of files, and i need to filter this list with some words that i put, line by line, in a file named filter.txt
. So I have to use findstr /g:filter.txt
.
But then I need to do something to the list files that matches, and since findstr
returns one row for each file, i have to read the matches line by line.
This is how i did it:
dir /b | findstr /g:filter.txt | for /F "delims=" %a in ('more') do del "%a"
SOLUTION:
It looks like that what I wanted to do was not reading from a pipe but just reading the output of another command in a batch file.
To do a single line read, you could use this:
echo Test | ( set /p line= & call echo %%line%%)
or you can use this, that works also with multi line input:
echo Test | for /F "delims=" %a in ('more') do @echo %a
(this trick of using more could be useful in some situations). But in my particular case, the solution is this:
for /F "delims=" %a in ('echo Test') do @echo %a
Thanks to everyone!