# NB: you can only do one command on a channel so we get the channel ## do the command give back the output then close the channel Note that the command ## must be a fully "shell punctuated and escaped" sub docmd { my $chan = $ssh2->channel() or $ssh2->die_with_error ; $chan->exec("($_[0]) 2>&1") ; # my $out = ""; while (!$chan->eof) { my $buffer = ""; my $bytes = $chan->read($buffer, 100) ; $ssh2->die_with_error if $bytes < 0 ; $out .= $buffer ; } return $out ; } #### print docmd("cd tmp; ls") ; print docmd("cd bin; ls") ; $ssh2->disconnect() ;