in reply to Re^2: use sysread to read non-blocking filehandle
in thread use sysread to read non-blocking filehandle
my $cmd = '/opt/rssh/bin/ssh'; my $machine = "remote_machine"; open(my $fh, "-|", "$cmd $machine \"hostname;sleep 5;uptime\" 2>&1") o +r die "cannot open fh"; my $flags = fcntl($fh, F_GETFL, 0) or die "\ncan't get flags for the p +ipe: $!\n"; fcntl($fh, F_SETFL, $flags | O_NONBLOCK) or die "\ncan't set flags: $! +\n"; my $out = $fh; my $bytes_read = -1; my $blocksize = 1024; my $result = ""; my $buf; $bytes_read = sysread($out, $buf, $blocksize); print "\nl buf content is:\n $buf \n"; close $out;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: use sysread to read non-blocking filehandle
by Corion (Patriarch) on Nov 04, 2014 at 14:37 UTC |