Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Make a nice buffer?
List,
I want to make a buffer for my application to write log data to.  I've
created a fifo (`mkfifo /tmp/buf`)  Then I made my PERL script that
reads from /tmp/buf.  Other programs open and write to /tmp/buf but when
they close then my program that is reading from /tmp/buf stops.  I want
the script that reads and buffers (then parses and other such stuff) not
to close when the other folks are done writing to the fifo at /tmp/buf.
Ideas?  Should I just loop and re-open after every close (seems bad).

/djb


Report this thread to moderator Post Follow-up to this message
Old Post
David Busby
03-27-04 04:14 AM


Re: Make a nice buffer?
On Thursday 25 March 2004 10:30 pm, David Busby wrote:
> List,
>   I want to make a buffer for my application to write log data to.  I've
> created a fifo (`mkfifo /tmp/buf`)  Then I made my PERL script that
> reads from /tmp/buf.  Other programs open and write to /tmp/buf but when
> they close then my program that is reading from /tmp/buf stops.  I want
> the script that reads and buffers (then parses and other such stuff) not
> to close when the other folks are done writing to the fifo at /tmp/buf.
> Ideas?  Should I just loop and re-open after every close (seems bad).
>
> /djb

Hi David,

I think that's the normal for pipes.  The way I understand it, a pipe is
simply a meeting point for someone openening a file for writing and one
opening a file for reading.  If you open first, your open won't complete
until the other proces tries to open soon.  Then their write open is directl
y
connected to your read open.  This means that when they close, you're closed
too.  As you can see from my code below, you have to re-open every time you
enter the loop.

Gary

#!/usr/bin/perl -w

my $VERSION='1.0.0';
# daemon to sit listening to a pipe and actioning print requests.
select(STDERR); $|=1;
select(STDOUT); $|=1;

my $inp;

chdir $ENV{RWDDATA} || die "cannot cd: $!\n";
die "pipe is missing\n" unless ( -p "rwfifo");

while (1) {
print "opening...";
open(FIN,"rwfifo") || die "cannot open pipe: $!";
print "Done\nreading pipe...";
$_=<FIN>;
chomp;
print "Done\n";
last if (/^quit/i);
next if (/loop/i);
print "executing rwlpr $_ loop .....";
print ((system "rwlpr $_ loop") ? "failed: $?\n" : "done\n");
print "reading pipe...";
}


--
Gary Stainburn

This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000


Report this thread to moderator Post Follow-up to this message
Old Post
Gary Stainburn
03-27-04 04:15 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:48 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.