cmv has asked for the wisdom of the Perl Monks concerning the following question:
Monks-
I apparently don't understand what is going on with pipes here in Unix, please help.
The intent is to create 2 child processes from a perl script. The script writes to one child process, who passes that (via named pipe) to the second child process, who sends the data to stdout. The script then reads the data from child 2 and prints it.
I've verified the pieces of this code work, but when I put it all together, I get nothing. What am I doing wrong?use strict; use warnings; use FileHandle; # Create named pipe... my $pipe = "/tmp/mypipe"; system("ksh -c 'if [ ! -p $pipe ]; then mkfifo $pipe; fi'"); # Setup input process... open(IN, '|-', "cat - > $pipe") || die "Can't open IN process: $!"; IN->autoflush(1); # Setup output process... open(OUT, '-|', "tail -f $pipe") || die "Can't open OUT process: $!"; OUT->autoflush(1); # Send input... my $input = '12345678901234567890123456789012345678901234567890'; print STDERR "Sending input...\n"; print IN $input; # Read output... print "Reading...\n"; my $line; while($line = <OUT>) { print $line }
Thanks
-Craig
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Pipes: Why does this fail?
by JavaFan (Canon) on Aug 26, 2010 at 14:06 UTC | |
by cmv (Chaplain) on Aug 26, 2010 at 14:31 UTC | |
by JavaFan (Canon) on Aug 26, 2010 at 15:35 UTC | |
Re: Pipes: Why does this fail?
by ikegami (Patriarch) on Aug 26, 2010 at 16:34 UTC | |
Re: Pipes: Why does this fail?
by kennethk (Abbot) on Aug 26, 2010 at 14:19 UTC |
Back to
Seekers of Perl Wisdom