Batch: what is the pipe | used for?
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
.
Comments
-
KKZiomek over 1 year
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 about 8 yearsYou can take the output from one command and pass it to the next command as input.
-
Aacini about 8 yearsBesides 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 about 8 yearsAnd 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.
-