sub cmd { my $self = shift; my $cmd = shift; my $ssh = $self->{ssh}; my $ch = $self->{ch}; unless ($ch) { $self->{ch} = $ch = $ssh->channel; $ch->ext_data('merge'); $ch->blocking(0); $ch->shell(); 1 while <$ch>; } print $ch "$cmd\n"; select(undef, undef, undef, 0.2); print $ch "print SSH2_cmd_done\n"; select(undef, undef, undef, 0.2); my @output; READ_LOOP: while (1) { local $_; while (<$ch>) { last READ_LOOP if /^SSH2_cmd_done/; push @output, $_; } sleep 1; } return @output; }