in reply to How to read from shell command and terminate it afterwards?
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");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to read from shell command and terminate it afterwards?
by chessgui (Scribe) on Feb 10, 2012 at 07:07 UTC | |
by ikegami (Patriarch) on Feb 10, 2012 at 07:53 UTC | |
by chessgui (Scribe) on Feb 10, 2012 at 08:18 UTC | |
by ikegami (Patriarch) on Feb 10, 2012 at 09:29 UTC | |
by chessgui (Scribe) on Feb 10, 2012 at 10:13 UTC | |
|