use IO::Select qw( ); # How long (in seconds) of not getting anything is considered done. use constant TIMEOUT => 2.0; open(my $pipe, '-|', 'mDNS -L "Service Name" _service._tcp domain'); my $buf = ''; # Wait to get something. my $rv = sysread($pipe, $buf, 64*1024, length($buf)); die $! if !defined($rv); # Wait until we stop getting if ($rv) { my $sel = IO::Select->new($pipe); for (;;) { if (!$sel->can_read(TIMEOUT)) { kill KILL => $pid; last; } my $rv = sysread($pipe, $buf, 64*1024, length($buf)); die $! if !defined($rv); last if !$rv; } } close($pipe); print("Got:\n$buf\n");
In reply to Re: How to read from shell command and terminate it afterwards?
by ikegami
in thread How to read from shell command and terminate it afterwards?
by Wen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |