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!
One of the most powerful shell operators is the pipe ( | ). The pipe takes output from one command and uses it as input for another. And, you're not limited to a single piped command—you can stack them as many times as you like, or until you run out of output or file descriptors.
What is a Pipe? Like most IPC mechanisms, pipes help facilitate communication between two applications and or processes using shared memory . This shared memory is treated as a file object in the Windows operating system.
The | command is called a pipe. It is used to pipe, or transfer, the standard output from the command on its left into the standard input of the command on its right. # First, echo "Hello World" will send Hello World to the standard output.
Usually, a batch file is created for command sequences when a user has a repetitive need. A command-line interpreter takes the file as an input and executes the commands in the given order. A batch file eliminates the need to retype commands, which saves the user time and helps to avoid mistakes.
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.
Like well commented by @aschipfl the space is piped too. so better use :
echo KKZiomek| find "KKZ"
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With