Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: What is a pipe and why would I want to use one?

by BrowserUk (Patriarch)
on Jul 10, 2002 at 05:28 UTC ( [id://180685]=note: print w/replies, xml ) Need Help??


in reply to What is a pipe and why would I want to use one?

Pipes are a way of connecting to programs together as they run so that the output from the first is fed into the input from the second. If you have ever typed type readme.txt | more(+) (or perhaps cat readme | more(+) if your a linux user), then that vertical bar (|) is an instruction to the command line processor (CLP) to use an (anonynous*) pipe btween the program type (**) or cat and the program more. This way, instead of the output from type (cat) coming straight onto the screen (via STDOUT) it is fed into the more program (via STDIN). It's this connection that is known as a pipe.

On some older, single tasking operating systems (OS's), meaning that the could only run one program at a time. ie. DOS. The way pipes where implemented was that the DOS CLP (command.com) would open a temporary output file on disk and pass that to the type command for it to place it's output in. When the type program finished, the CLP would close and reopen the temporary file for input and pass this to the more program as STDIN. The more program would then read the temporary file and display it 24 or 34 lines at a time depending on how big your screen was. Luckily, this ludicrous situation is no longer true in DOSish (Windows) OS's and they do the sensible thing, as all unix OS's have always done (and even their forerunners, DEC RSTS/E and RSX did way back) and simply share a memory buffer between the two programs that they can write to and read from as if the pipe was a file.

This very simple concept is the very essense of the "unix way". It is the glue which allows lots of small programs that do one (usually simple) task very well to be combined together to perform lots of different functions.

I am sure that you will get lots of good clear examples of how the concept of pipes can be useful with Perl programs from the other guys that have much greater knowledge on that than I do.

Have fun with pipes. They are very useful.

+. Of course, this an inefficient way of pausing a file, more < readme.txt or even  more readme is much better, but it's only here by way of illustration.

*. On windows system's there are also things called named pipes. These can be used to connect between programs running on different machines. The way these work is somewhat more complicated, but the principles are much the same. To the programs running they simple look like files, and are read and written using the same calls as files.

**. Actually, on modern windows OS's, type isn't a seperate program stored in a .com or .exe file, its a built-in command within the CMD.exe CLP, but the effect amounts to the same thing.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://180685]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2025-01-14 15:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (42 votes). Check out past polls.