Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by fsn (Friar)
on Jul 10, 2002 at 18:30 UTC ( [id://180827]=note: print w/replies, xml ) Need Help??


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

This is a very very simple (and probably Linuxcentric) attempt to illustrate how you can send data from one program to another using a pipe:

./Daddy.pl:

#!/usr/bin/perl $i=0; open SESAME,"|./Kiddy.pl"; # Open up the pipe while ( $i++<10) { print SESAME "Testing IPC with pipes. Line $i.\n"; # Prin +t to pipe } close SESAME; # This (or the termination of the program) # closes the pipe. The other side recieves this # as an EOF (End OF File).

./Kiddy.pl:

#!/usr/bin/perl while ($in=<STDIN>) { # Read from <STDIN> until <EOF> chomp $in; # Remove <NL> print "By Kiddy.pl: $in\n"; # Print out what we read }

There are some extra fluff in Kiddy.pl, the use of chomp and $in instead of $_ f.ex., but I kept it there to make it more clear, at least to me.

If you run the above you would get this:

$ ./Daddy.pl
By Kiddy.pl: Testing IPC with pipes. Line 1.
By Kiddy.pl: Testing IPC with pipes. Line 2.
By Kiddy.pl: Testing IPC with pipes. Line 3.
By Kiddy.pl: Testing IPC with pipes. Line 4.
By Kiddy.pl: Testing IPC with pipes. Line 5.
By Kiddy.pl: Testing IPC with pipes. Line 6.
By Kiddy.pl: Testing IPC with pipes. Line 7.
By Kiddy.pl: Testing IPC with pipes. Line 8.
By Kiddy.pl: Testing IPC with pipes. Line 9.
By Kiddy.pl: Testing IPC with pipes. Line 10.
$

Note that Daddy.pl is not printing to the screen at all, Kiddy.pl is doing all that.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-19 20:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found