Glib::IO watcher unbuffered?
- From: "Philipp E. Letschert" <phil uni-koblenz de>
- To: gtk-perl-list gnome org
- Subject: Glib::IO watcher unbuffered?
- Date: Fri, 19 Jan 2007 09:24:53 +0100
Hi,
I would like to have unbuffered output processing from an external command
(command prints a line, sleeps, prints a line, sleeps ...):
$| = 1;
open my $pipe, "$cmd |"
or croak("Failed running $cmd: $!\n");
$pipe->autoflush(1);
my $watcher;
$watcher = Glib::IO->add_watch( fileno( $pipe ), ['in', 'hup'],
sub { watcher_callback($self, $pipe, $watcher); } );
sub watcher_callback {
my ($self, $pipe, $watcher) = @_;
$| = 1;
$pipe->autoflush(1);
if ( eof( $pipe ) ) {
Gtk2::Helper->remove_watch( $watcher );
close( $pipe );
}
else {
my $line = <$pipe>;
print $line; # printed with a delay, still buffering?
}
return 1;
}
I tried to have $line processed without delay (autoflush all handles
everywhere...), but the watcher only prints bunches of lines after some longer
delay.
Why does the buffering happen and how to turn it off?
Thanks, Phil
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]