Glib::IO->add_watch



Hi all. I'm trying to adapt some code I have for tailing the output of
an app. When I fork using open() ... things work ( I have some issues
with tail never exiting, but that's to be expected ). When I open a
filehandle for reading these redirected log files however, my callback
I passed to add_watch() gets called in a busy loop, and nothing else
happens. I assume I'm just doing something simple wrong? What is that
thing? :) Thanks ...

Dan

---

# Redirect STDOUT / STDERR to log files
my $app_log_path = "$logdir/app_" . $timestamp . ".log";
my $err_log_path = "$logdir/err_" . $timestamp . ".log";

my ( $STDOUT_READER , $STDERR_READER );

say( "Redirecting:\nSTDOUT: $app_log_path\nSTDERR: $err_log_path" );
open STDOUT, '>', $app_log_path or die "Can't redirect STDOUT: $!";
open STDERR, '>', $err_log_path or die "Can't redirect STDERR: $!";

# open $STDOUT_READER , "<" , $app_log_path or die( "Can't open stdout
log file!: $!" );
open( $STDOUT_READER, "tail -f $app_log_path |" )
    || die( "Can't fork!\n" . $! );

# open $STDERR_READER , "<" , $err_log_path or die( "Can't open stderr
log file!: $!" );
open( $STDERR_READER, "tail -f $err_log_path |" )
    || die( "Can't fork!\n" . $! );

Glib::IO->add_watch( fileno( $STDOUT_READER ) , ['in'] , sub {
    my ( $fileno, $condition ) = @_;
    # parse logs and write to textview
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]