in reply to Perl IPC?
There's also named pipes, which are nice in cases when there isn't a relationship between the communicating processes (although you could use them in this case if you want).pipe(README, WRITEME); if (fork) { #parent code while (<README>) { # you can do other stuff in here besides reading $output .= $_; } close(README); } else { # child code print WRITEME "interesting stuff"; close(WRITEME); }
With named pipes, readers and writers will block until their counterpart appears at the other side unless you open the fifo using +<. All of these examples are out of the Perl Cookbook, chapter 16.# writer open(FIFO, "> /path/to/named.pipe"); print FIFO "Interesting stuff"; close(FIFO); #reader open(FIFO, "< /path/to/named.pipe"); while(<FIFO>) { $output .= $_; } close(FIFO);
Update: Forgot to mention you have to create the named fifo first, from the shell. On most systems this is
mkfifo /path/to/named.pipeOlder systems use mknod.
|
|---|