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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.