in reply to SSH not working with TK

I don't see your comparison between your working snippet, and your failing sub. The failing sub dosn't resemble the working snippet at all. This snippet works on linux, you might try to substitute your working snippet and see if it goes.
#!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; use Tk; my $mw = MainWindow->new; my $text = $mw->Text(); $text->pack; $text->insert('end',"Net::SSH::Perl Test\n"); $mw->Button( -text => "SSH", -command => \&do_ssh )->pack; $mw->Button( -text => "Exit", -command => sub{exit} )->pack; MainLoop; sub do_ssh{ my $user = "z"; my $password = "ztest"; my @hosts = qw(localhost); foreach my $host (@hosts){ my $cmd = "/usr/bin/uptime"; my $ssh = Net::SSH::Perl->new( $host, port => 22 , protocol => 2, # debug => 1, ); $ssh->login($user,$password); my($out) = $ssh->cmd($cmd); my ($time,$uptime) = (split /\s+/,$out)[1,3]; chop $uptime; $text->insert('end', "$out\n"); $text->insert('end', "$host has been up $uptime\n"); } }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: SSH not working with TK
by veeruch (Sexton) on Jul 11, 2006 at 05:03 UTC
    same function telnet is wroking fine in TK programs then why SSH not wroking?
    sub ConnectTelnet { print LOG " [FunctionName][ConnectTelnet] \n"; my $TelnetObject = new Net::Telnet(Timeout => 100,Errmode => ' +return'); if($TelnetObject->open("$HostName")) { if(!$TelnetObject->login($TelnetUserId,$UnixPassword) ) { print LOG " Unable to connect telnet \n"; &ErrorNotification(ERR_LOGIN_TITLE,ERR_LOGIN_MSG); $MainScreenObject -> Unbusy( -recurse => '1' ); return(0); } else { print LOG "connected Sucesfully"; } } else { print LOG " Unable to connect network \n"; &ErrorNotification("ERR_CON_TITLE","ERR_CON_MSG"); } #For retrieving telnetobject decalring globally $TelnetObjectRef = $TelnetObject; return($TelnetObject); }

      is Net::SSH::W32Perl wroking with Tk functions?
      bcoz i have given code Net::SSH::W32Perl it is wroking if
      I use just Tk in That code (like This use Tk;).it is giving errors like below

      indamaaaf31786: Reading configuration data /.ssh/config indamaaaf31786: Reading configuration data /etc/ssh_config indamaaaf31786: Connecting to host, port 22. indamaaaf31786: Socket created, turning on blocking... indamaaaf31786: Remote protocol version 2.0, remote software version O +penSSH_3.7.1p2-pwexp26 "makerandom" is not exported by the Crypt::Random module at E:/perl/si +te/lib/Crypt/Random/Generator.pm line 12 "makerandom_itv" is not exported by the Crypt::Random module at E:/per +l/site/lib/Crypt/Random/Generator.pm line 12 "makerandom_octet" is not exported by the Crypt::Random module at E:/p +erl/site/lib/Crypt/Random/Generator.pm line 12 Can't continue after import errors at E:/perl/site/lib/Crypt/Random/Ge +nerator.pm line 12 BEGIN failed--compilation aborted at E:/perl/site/lib/Crypt/Random/Gen +erator.pm line 12, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Crypt/Random.pm line + 18, <GEN0> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Crypt/Random.pm +line 18, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Crypt/DH.pm line 6, +<GEN0> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Crypt/DH.pm line + 6, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/Perl/Kex/DH1 +.pm line 13, <GEN0> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Net/SSH/Perl/Kex +/DH1.pm line 13, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/Perl/Kex.pm +line 6, <GEN0> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Net/SSH/Perl/Kex +.pm line 6, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/Perl/SSH2.pm + line 6, <GEN0> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Net/SSH/Perl/SSH +2.pm line 6, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/W32Perl/SSH2 +.pm line 7, <GEN0> line 1. BEGIN failed--compilation aborted at E:/perl/site/lib/Net/SSH/W32Perl/ +SSH2.pm line 7, <GEN0> line 1. Compilation failed in require at E:/perl/site/lib/Net/SSH/Perl.pm line + 55, <GEN0> line 1.

      20060711 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

        it is wroking for TK
        The problem occurs if you are running Crypt::Random version
        1.13. The problem is fixed in version 1.25 (and maybe earlier, I don't know).
        The following lines:

        version 1.13

        *import = \&Exporter::import; @EXPORT_OK = qw( makerandom makerandom_itv <br>makerandom_octet );
        Should be changed to:

        version 1.25
        BEGIN { *import = \&Exporter::import; @EXPORT_OK = qw( makerandom makerandom_itv <br>makerandom_octet ); }

        20060711 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips