Thanks for the input. I'm going to be testing different solutions. I know
one thing that I need to address is the ability to determine the last
location read from the file. If the script needs to restart for any reason,
I need to make sure that the log isn't being duplicated in the database. Is
there a [tell] comparative in Win32?

-----Original Message-----
From: Philip Newton [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 15, 2000 11:47 AM
To: 'Morehouse, Ken'; Win32 Perl Admin ActiveState LS (E-mail)
Subject: Re: Tail for NT


Morehouse, Ken wrote:
> Has anyone used the Win32 port of tail.exe successfully? I 
> can use it to -f a file without issue when the output goes
> to STDOUT. If I try to pipe the output to another process,
> tail no longer sees additions to the file. I can tail a file
> without -f to a pipe okay.

Does it not show additions at all? Or only after a long time.

My guess on what's happening here is that tail.exe is asking whether its
output is a TTY (using isatty() or equivalent; -t in perl), and if it isn't,
it buffers its output rather than writing directly. So what would happen is
that tail monitors the file, and when something gets written, tail writes
the new lines to its output buffer, but doesn't flush its buffer to the pipe
until the buffer is full.

Compare this bit from `perldoc perlfaq5`:

    In most stdio implementations, the type of output buffering and
    the size of the buffer varies according to the type of device.
    Disk files are block buffered, often with a buffer size of more
    than 2k. Pipes and sockets are often buffered with a buffer size
    between 1/2 and 2k. Serial devices (e.g. modems, terminals) are
    normally line-buffered, and stdio sends the entire line when it
    gets the newline.

To find out whether this is the cause of your problem, you could try to tail
-f a file that grows quickly, and see whether the pipe gets its output in
spurts; this would indicate that it's getting a bufferful at a time.

I don't know of a way to turn off buffering in a program that you didn't
write yourself. But you could re-implement tail in Perl; then you have
control over buffering. If you use "$| = 1;", then your output should always
go directly to STDOUT, regardless of whether STDOUT is connected to a tty, a
file, or another process.

File::Tail (available from CPAN, in directory authors/id/M/MG/MGRABNAR)
could help you if you choose to reimplement the command in Perl.

Cheers,
Philip
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin

Reply via email to