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?
./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).
#!/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 }
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. $
|
|---|