Batch: what is the pipe | used for?
Pipe [|]: Redirect standard output of commandA to standard input of commandB
echo KKZiomek | find "KKZ"
will redirect the
echo KKZiomek in the input of the
FIND and be used as second parameter of it.
The pipe is used to send the output of one command to the input of another command.
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
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 almost 7 yearsYou can take the output from one command and pass it to the next command as input.
Aacini almost 7 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 almost 7 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.