WORKING: ... debug1: Sending command: /usr/bin/ksh -c "cat /etc/passwd" debug2: channel 0: request exec confirm 1 debug2: fd 4 setting TCP_NODELAY debug2: callback done debug2: channel 0: open confirm rwindow 0 rmax 32768 debug2: channel_input_confirm: type 99 id 0 debug2: PTY allocation request accepted on channel 0 debug2: channel 0: rcvd adjust 2097152 debug2: channel_input_confirm: type 99 id 0 debug2: exec request accepted on channel 0 debug2: channel 0: rcvd eof debug2: channel 0: output open -> drain debug2: channel 0: obuf empty debug2: channel 0: close_write debug2: channel 0: output drain -> closed ... NOT WORKING: ... debug1: Sending command: /usr/bin/ksh -c "cat /etc/passwd" debug1: channel request 0: exec debug1: fd 4 setting TCP_NODELAY debug2: callback done debug1: channel 0: open confirm rwindow 0 rmax 32768 debug2: channel 0: rcvd adjust 131072 debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 debug1: channel 0: write failed debug1: channel 0: close_write debug1: channel 0: output open -> closed debug1: channel 0: rcvd eof debug1: channel 0: rcvd close debug1: channel 0: close_read debug1: channel 0: input open -> closed debug3: channel 0: will not send data after close debug1: channel 0: almost dead debug1: channel 0: gc: notify user debug1: channel 0: gc: user detached debug1: channel 0: send close debug1: channel 0: is dead debug1: channel 0: garbage collecting debug1: channel_free: channel 0: client-session, nchannels 1 debug3: channel_free: status: The following connections are open: #0 client-session (t4 r0 i3/0 o3/0 fd -1/-1) debug3: channel_close_fds: channel 0: r -1 w -1 e 7 debug1: fd 1 clearing O_NONBLOCK debug1: fd 2 clearing O_NONBLOCK Connection to host closed. debug1: Transferred: stdin 0, stdout 0, stderr 30 bytes in 15.1 seconds debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 2.0 debug1: Exit status 0 ... #### 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"; }