As to your error, you may need a pseudo tty, called a pty. Google for it. There is a perl module IO::Pty , but in the case of ssh2, you really should switch to a Perl method like Net::SSH2
Certain programs are written to make sure it has a terminal to output to. The program "top" is like that, you will get the same error as yours, unless you use IO::Pty.