use strict; use warnings; use IO::Select; my $cmd1 = "cat /etc/passwd"; my $sshcmd = "/usr/bin/ssh -t -i \$HOME/.ssh/mypubkey -o 'StrictHostKeyChecking no' user\@host $cmd1"; # Prove command works... my $out = `$sshcmd`; print STDERR "OUT:\n$out"; #open(IFILE, "$cmd1 |") || die "Bad open"; # This will work open(IFILE, "$sshcmd |") || die "Bad open"; # This does not my $select = IO::Select->new(); $select->add(\*IFILE); my @ready; while ( @ready = $select->can_read(5) ) { foreach my $fh (@ready) { my $line = <$fh>; STDERR "line=$line"; if(eof($fh)) { $select->remove($fh); close($fh) || warn "Close problem on fh: $fh"; } } }