#!/usr/bin/perl
use warnings;
use 5.6.0;
use IO::Handle;
STDOUT->autoflush(1);
STDERR->autoflush(1);
$SIG{PIPE} = sub { die "SIGPIPE: (@_) $!\n" };
$/ = undef;
while(1) {
print "Opening pipe: ";
open $pipe, "< tst.fifo" or die "Can't open pipe: $!\n";
$pipe->autoflush(1);
print "got pipe, reading:\n";
print map ": $_\n", split "\n", scalar <$pipe>;
print "Pipe done, closing: ";
close $pipe or die "Can't close pipe: $!\n";
print "done.\n";
print "Taking a long time... ";
sleep 3;
}
exit;
####
#!/usr/bin/perl
use warnings;
use 5.6.0;
use IO::Handle;
STDOUT->autoflush(1);
STDERR->autoflush(1);
$SIG{PIPE} = sub { die "SIGPIPE: (@_) $!\n" };
$delay = shift || 0;
@data = map "$_\n", split "\n", <<'EOD';
This is some silly,
stuff to be sent
to the pipe where hopefully
it will be read.
EOD
while(@data and $_ = shift @data) {
open $pipe, "> tst.fifo" or die "Can't open pipe: $!\n";
$pipe->autoflush(1);
print $pipe $_;
close $pipe or die "Can't close pipe: $!\n";
sleep $delay if $delay;
}
exit;
####
Opening pipe: got pipe, reading:
: This is some silly,
: stuff to be sent
: to the pipe where hopefully
: it will be read.
Pipe done, closing: done.
Taking a long time... done.