J
Jim Mozley
I need to send messages to an application whose interface for this
purpose is a named pipe (fifo).
I have a script to write to the pipe that is executed (via swatch)
whenever a certain syslog message is pattern matched. They problem is
that when I receive a group of messages nearly simultaneously I
sometimes see the resulting output in the application as one message.
E.g. the messages
"help me"
"help me too"
"and me"
should appear as three separate messages but on rare occations I get
"help me help me too and me"
shown in the application as one message.
I current do the following to write to the pipe:
open (PIPE, "> $pipe") or die "Cannot open pipe $!";
flock(PIPE,2);
print PIPE "$cmd";
close PIPE or die "Cannot close pipe $!";
I was wondering if I should use the following code below (taken from an
example I saw for writing to a pipe that I propose to put in a package):
my $fh = new IO::File;
sysopen( $fh, $pipe, O_SYNC|O_WRONLY|O_APPEND )
or croak "could not open $cmdfile for writing: $!";
flock( $fh, LOCK_EX );
seek( $fh, 0, SEEK_END );
my $numofbytes = syswrite( $fh, $cmd, length($cmd) );
flock( $fh, LOCK_UN );
carp "No data written!" unless $numofbytes;
Is one better than the other for this purpose?
Thanks,
Jim
purpose is a named pipe (fifo).
I have a script to write to the pipe that is executed (via swatch)
whenever a certain syslog message is pattern matched. They problem is
that when I receive a group of messages nearly simultaneously I
sometimes see the resulting output in the application as one message.
E.g. the messages
"help me"
"help me too"
"and me"
should appear as three separate messages but on rare occations I get
"help me help me too and me"
shown in the application as one message.
I current do the following to write to the pipe:
open (PIPE, "> $pipe") or die "Cannot open pipe $!";
flock(PIPE,2);
print PIPE "$cmd";
close PIPE or die "Cannot close pipe $!";
I was wondering if I should use the following code below (taken from an
example I saw for writing to a pipe that I propose to put in a package):
my $fh = new IO::File;
sysopen( $fh, $pipe, O_SYNC|O_WRONLY|O_APPEND )
or croak "could not open $cmdfile for writing: $!";
flock( $fh, LOCK_EX );
seek( $fh, 0, SEEK_END );
my $numofbytes = syswrite( $fh, $cmd, length($cmd) );
flock( $fh, LOCK_UN );
carp "No data written!" unless $numofbytes;
Is one better than the other for this purpose?
Thanks,
Jim