简体   繁体   English

perl File :: Tail延迟

[英]perl File::Tail delay

I'm using the perl File::Tail library to tail the output of a file and parse it's output. 我正在使用perl File :: Tail库来尾部文件的输出并解析其输出。

Everything's working fine except there seems to be about a 10 second delay after I start the script before it starts outputting. 一切工作正常,除了启动脚本之后开始输出之前似乎有10秒的延迟。 After the first read, it works fine and all output is instantaneous. 第一次读取后,它可以正常工作,并且所有输出都是瞬时的。 All of the writes during the delay seem to be outputted once it starts working, so I'm not losing any data. 一旦开始工作,延迟期间的所有写操作似乎就会输出,因此我不会丢失任何数据。 I don't think it has nothing to do with the file I'm reading because running a regular "tail -f" works instantly. 我认为这与我正在读取的文件无关,因为运行常规的“ tail -f”可立即生效。

Heres the entire script: 这是整个脚本:

#!/bin/perl
use File::Tail;

$file=File::Tail->new("file.txt");

while (defined($line=$file->read)) {
    print "$line\n";
}

I copied this from an example somewhere online. 我从在线某个地方的示例中复制了此内容。 I'm not very familiar with perl or File::Tail I'm hoping I'm doing something wrong. 我对perl或File :: Tail不太熟悉,希望我做错了什么。 Any help would be appreciated. 任何帮助,将不胜感激。

See the interval option in the documentation: 请参阅文档中的interval选项:

The initial number of seconds (real number) that will be spent sleeping, before the file is first checked. 在首次检查文件之前,将花费在睡眠上的初始秒数(实数)。 Default is ten seconds, meaning "File::Tail" will sleep for 10 seconds and then determine, how many new lines have appeared in the file. 默认值为十秒钟,这意味着“ File :: Tail”将休眠10秒钟,然后确定文件中出现了几行新内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM