print to STDOUT works but FH1 does not with FIFO named pipe

G

gnari

Rocky said:
On Wed, 14 Jul 2004 14:11:44 -0400, Paul Lalli wrote:

[reading from pipe to files]
My mistake. I left the FH1 and FH2 out of the posted code. When I run
this script and just print it to standard out the data will stream
perfectly as it comes in from the FIFO. If I print it to FH1,FH2 and tail
-f the output files I get nothing. That, I guess, is what I should have
said from the beginning

yes, you should have mentioned that you test this with grep.

you are not seing any output because you are not waiting long enough.
the data is still in file or pipe buffers when you probably interrupt
your program.

gnari
 
A

Anno Siegel

Rocky said:
so posted sir.

#!/usr/bin/perl
use warnings;
use strict;
$| = 1;
#open(FH3,"</var/run/syslogdpipe") or die "$!\n";
open(FH3,"</storage/tempmail") or die "$!\n";
open(FH1,">./mx0out") or die "$!\n";
open(FH2,">./mx1out") or die "$!\n";
while (<FH3>)
{
my $line = $_;
if ($line =~ /^.*svr-linux.*$/)
{
print FH1 "mx00 $line\n";
}
elsif ($line =~ /^.*192\.168.*$/)
{
print FH2 "mx01 $line\n";
}
}

If you want to see each line as it appears in the output files, turn
on auto-flushing for them. Add these lines after the last "open":

do { select $_; $| = 1 } for \ *FH1, \*FH2;
select STDOUT;

Another potential problem is that you must wait for the program to
start before you run "tail -f" on the output file(s). If you don't,
"tail" will try to follow the last output file while the program
has created a new one.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top