Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch: what is the pipe | used for?

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!

like image 498
KKZiomek Avatar asked Oct 22 '15 23:10

KKZiomek


People also ask

What is pipe CMD?

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.

Does pipe work in Windows?

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.

Does pipe work in CMD?

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.

What is batch used for?

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.


2 Answers

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"
like image 166
SachaDee Avatar answered Oct 19 '22 16:10

SachaDee


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.

like image 6
SomethingDark Avatar answered Oct 19 '22 16:10

SomethingDark