in reply to Threads or no Threads
I'm not sure what you want. Are you looking to be notifie when the child has been idle for a certain amount of time?
use strict; use warnings; use IO::Select qw( ); my $timeout = 30.000; # Notify user after idle for this many secs my $command = '...'; # The command to execute. my $from_child = ''; # Receives the output of the command. open(my $fh_from_child, "$command |") or die("Unable to launch $command: $!\n"); my $sel = IO::Select->new($fh_from_child); for (;;) { my @r = $sel->can_read($timeout); if (!@r) { print("Another $timeout seconds has gone by...\n"); redo; } read($fh_from_child, $from_child, 4096, length($from_child)) or last; } print($from_child);
Tested on FreeBSD. It won't work on Windows (since you can't select pipes).
|
---|