If there are severals filehandles parallel at the same time, I can do a loop and next to read the filehandels.
Here I just use a simple example to try non-blocking and sysread. So just one filehandle, set to non blocking, then read.
If I just use once sysread to try, it is still empty. Here is the code, what is wrong in the code?
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
fcntl($fh, F_SETFL, $flags | O_NONBLOCK) or die "\ncan't set flags: $!
my $out = $fh;
my $bytes_read = -1;
my $blocksize = 1024;
my $result = "";
$bytes_read = sysread($out, $buf, $blocksize);
print "\nl buf content is:\n $buf \n";
Maybe you want to learn what "nonblocking" really means?
In short, "nonblocking" means that the sysread call will return immediately and tell you how many bytes were read at this time. If your filehandle has nothing to read, it will not block. Blocking means "wait until data is avilable".