http://www.perlmonks.org?node_id=575285


in reply to Reading from a Named Pipe

alarm will interrupt a read.

Replies are listed 'Best First'.
Re^2: Reading from a Named Pipe
by nzgrover (Scribe) on Sep 28, 2006 at 21:28 UTC
    ah ha! So something like:
    if (-p $named_pipe_name) { eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required alarm $timeout; if (sysopen(FIFO, $named_pipe_name, O_RDONLY)) { while(my $this_line = <FIFO>) { chomp($this_line); $result .= $this_line; } close(FIFO); } else { $errormsg = "ERROR: Failed to open named pipe $named_pipe_name + for reading: $!"; } alarm 0; }; if ($@) { if ($@ eq "alarm\n") { # timed out $errormsg = "Timed out reading from named pipe $named_pipe_nam +e"; } else { $errormsg = "Error reading from named pipe: $!"; } } else { # didn't time out print STDOUT "$result\n"; } }