use strict; use warnings; use IO::Select; my $cmd = '"cat /etc/passwd"'; my $login = 'usr@host'; my $pkey = "$ENV{HOME}/.ssh/privateKey"; my @shell = ( '/usr/bin/ksh' => ( -c => $cmd, )); my @sshcmd = ('/usr/bin/ssh' => ( -t => (), -v => (), #-vv => (), #-vvv => (), -i => $pkey, -o => 'StrictHostKeyChecking no', $login, @shell, )); open (IFILE, '-|') || exec @sshcmd; my $select = IO::Select->new(); $select->add(\*IFILE); my @ready; while ( @ready = $select->can_read(5) ) { foreach my $fh (@ready) { my $line = <$fh>; print STDERR "line=$line"; if(eof($fh)) { $select->remove($fh); close($fh) || warn "Close problem on fh: $fh"; } } } close(IFILE); END{ print STDERR "\$!: $!\n"; }