#!/usr/bin/perl -w
my($host, $username, $password) = 
	('roitsystems.com','ogerr','dilb3rt1');

use strict;
use Net::SSH::Perl;
use IO::Pty;

my $pty = new IO::Pty;

my $slave = $pty->slave;

my $ssh = Net::SSH::Perl->new($host, debug => 1, protocol => 1);
$ssh->login($username, $password);

$ssh->register_handler("stdout", sub {
    my($channel, $buffer) = @_;
    my $str = $buffer->bytes;
	print "stdout: $str\n";
	my $cmd = <$pty> || '';
	print "STDOUT: $cmd\n";
	$channel->send_data($cmd) if $cmd;
});

$ssh->register_handler("stderr", sub {
    my($channel, $buffer) = @_;
    my $str = $buffer->bytes;
    print "stderr: $str\n";
	my $cmd = <$pty>||'';
	print "STDIN: $cmd\n";
	$channel->send_data($cmd) if $cmd;
});

## After registering the handler, we run the command.
my $cmd = 'perl -d svgtermd/sshc.pl';
$ssh->cmd($cmd);
while ( $cmd = <STDIN>) {
	print $pty $cmd;
	$ssh->cmd($cmd);
}
