Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8834093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:56:06+00:00 2026-06-14T08:56:06+00:00

I was wondering if it is possible to read from a pipe in a

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:56:07+00:00Added an answer on June 14, 2026 at 8:56 am

    Excuse me, I think there is a confusion here…

    You said you want to read from a pipe. A pipe is used to redirect the output of one command into the input of another command; the second command is called filter. For example, in

    dir /b | findstr /g:filter.txt
    

    there is a pipe between dir and findstr commands. A pipe is always established between two processes. There is no way to read the data that flow from dir command to findstr command (that is the only pipe that exist here). However, you can read from the output of findstr command.

    If we insert an additional filter, the behavior is the same. For example, in

    dir /b | findstr /g:filter.txt | more
    

    there are two pipes, but there is no way to read from anyone of them. However, you can read from the output of the last command (more in this case). What is the native Batch solution to read the output of one command? It is the FOR /F command. For example, the native way to get echo command output in:

    echo Test | for /F "delims=" %a in ('more') do @echo %a
    

    is:

    for /F "delims=" %a in ('echo Test') do @echo %a
    

    Please note that in the first example the %a parameter does NOT get the information from the pipe that exist between echo and for commands, but from the output of more command.

    In the same way, the natural method to achieve this task:

    dir /b | findstr /g:filter.txt | for /F "delims=" %a in ('more') do del "%a"
    

    is this way:

    for /F "delims=" %a in ('dir /b ^| findstr /g:filter.txt') do del "%a"
    

    that process the multi-line output of findstr command.

    Second method is not just faster than the former, but it is also clearer because the inclusion of a more command that really do nothing may lead to undesired misconceptions or errors.

    Antonio

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering, is it possible to read/write a file from/to a certain user
I was wondering if it was possible to read a text file that was
Just wondering is it possible to build CLI app that can be run from
I'm wondering if it is possible to list/read emails from Silverlight app in Windows
I don't think it's possible from what I've read, but wanted to see if
I was wondering if it is possible to read speaker output from XNA. For
Just wondering if it is possible to figure out who has read files from
Possible Duplicate: How to read logical data from a file in R I generated
I am wondering if the below is possible in Spring Read a property file
I know it's possible to read in values from the grails-app/conf/Config.groovy but i was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.