Batch: what is the pipe | used for?

11,575

Solution 1

Pipe [|]: Redirect standard output of commandA to standard input of commandB

http://www.robvanderwoude.com/redirection.php

example :

echo KKZiomek | find "KKZ"

will redirect the echo KKZiomek in the input of the FIND and be used as second parameter of it.

Solution 2

The pipe is used to send the output of one command to the input of another command.

For example, del /p will ask for confirmation when you delete files. However, you can pipe echo y to it to send a y to the del command and del will act as if the user had pressed y.

Share:
11,575
KKZiomek
Author by

KKZiomek

A.

Updated on June 25, 2022

Comments

  • KKZiomek
    KKZiomek 3 months

    Hello stackoverflow users!

    I'm not really new to batch. I just never used pipes | in batch and even after I read reference on ss64.com I don't understand what's the pipe used for.

    At first I thought it is OR operator or something (obviously I know now it's not).

    I only know that it's located between two lines (commands) like &, but I still don't get what it does exactly, and how it is used practically in code.

    Thanks for answering!

    • Squashman
      Squashman almost 7 years
      You can take the output from one command and pass it to the next command as input.
    • Aacini
      Aacini almost 7 years
      Besides the "pipeline" function already explained, the vertical bar is also used as bitwise OR operator in SET /A command, like this: set /A "var=5 | 2"
    • Squashman
      Squashman almost 7 years
      And to confuse even more there is the double pipe ||. Which is used for conditional execution. Execute the second command if the first command was unsuccessful.