my $cmd = '/opt/rssh/bin/ssh'; my $machine = "remote_machine"; open(my $fh, "-|", "$cmd $machine \"hostname;uptime\" 2>&1") or die "cannot open fh"; my $flags = fcntl($fh, F_GETFL, 0) or die "\ncan't get flags for the pipe: $!\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 = ""; while ($bytes_read) { my $buf; $bytes_read = sysread($out, $buf, $blocksize); if (defined($bytes_read)) { if ($bytes_read == 0) { close($out); last; } else { print "\nbuf content\n"; $result.= $buf; } }else { if ($! == EAGAIN()) { print "\nEAGAIN is set\n"; last; } else { last; } } } print "\nresult is: $result \n";