[tpm] buffering problem on input from shell command

Madison Kelly linux at alteeve.com
Fri Mar 7 18:26:39 PST 2008


Hi all,

   Another question, if I may. :)

   I've been struggling with a buffering problem... I listen to the 
output from a shell command ('dbus-monitor --system --profile', 
specifically). When certain strings come up, I need to perform some 
tasks. The problem is, the data coming in is cached.

   I figured it was the usual "suffering from buffering" issue, and 
tried various things I could to make the filehandle hot. Finally in 
reading some of the docs I realized that making a filehandle hot only 
works on output, not input. The only option I saw there was 'getc()', 
but if I understand that right, it will flush after every byte, where I 
want to flush on newline '\n'... Is this possible? Am I approaching this 
the wrong way entirely?

   Here is the exact code... (cleaned up for the post)

my $shell_call="dbus-monitor --system --profile 2>&1 |";
my $dm=IO::Handle->new();
my $child_pid=getc ($dm, $shell_call) or die "Error: $!\n";
$dm->autoflush(1);
push (@::pids, $child_pid);
while (<$dm>)
{
	chomp;
	my $line=$_;
	$line=~s/\s+/ /g;
	my ($type, $unix_time, $serial, $unknown1, $udi, $interface, 
$action)=split/ /, $line, 7;
	next if ( $type ne "sig" );
	next if ( $udi !~ /\/org\/freedesktop\/Hal/ );
	next if ( $udi =~ /acpi_BAT(\d+)$/ );
	
	# Go ahead and scan.
	&scan_devices($conf, $dbh);
}
$dm->close();

   Thanks!

Madi


More information about the toronto-pm mailing list