Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^2: Pipes: Why does this fail?

by cmv (Chaplain)
on Aug 26, 2010 at 14:31 UTC ( #857469=note: print w/replies, xml ) Need Help??

in reply to Re: Pipes: Why does this fail?
in thread Pipes: Why does this fail?


Thanks for the quick help. I've modified the test script (see below) and it now works as expected.

One question though. Using the tail -f line below causes the script to fail, reverting to the cat line makes it work. I don't understand why?



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: $!"; open(OUT, '-|', "cat $pipe") || die "Can't open out process: $!"; OUT->autoflush(1); my $i=0; print STDERR "Sending input...\n"; print IN "This is message $i\n"; # Read output... print "Reading...\n"; my $line; while($line = <OUT>) { $i++; print $line; print IN "This is message $i\n"; sleep 1; }

Replies are listed 'Best First'.
Re^3: Pipes: Why does this fail?
by JavaFan (Canon) on Aug 26, 2010 at 15:35 UTC
    My guess would be that 'tail -f' first tries to seek to the end - but a named pipe isn't seekable. Why it doesn't die, I do not know.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://857469]
[LanX]: Eily your turn to provide a pic :)
[Eily]: occupe toi de tes oignons
LanX could do a zoom out in animated gif ...
[LanX]: heh
[marto]: get with the times, webm :P
[LanX]: didn't know this expression xD
[Eily]: :)
[Eily]: if you want to learn French expressions you can give a look to @bouletcorp on twitter
[Eily]: s/to/at/
[LanX]: I'd rather buy another Fluide Glacial

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2017-12-14 16:30 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (398 votes). Check out past polls.