Hi:
 I am trying use the following gui program to  let user to
login to a remote box dump the some process information.
What I wanted is that let the perl:expect:spawn session
stdout dump on the to TK:Text window. If I use tie to display
text on the  tk window,  the expect:spawn is failing. If I commected
out the tie command line the code works fine, bu t out put appears
on the unix shell window and not the perl:tk:text window.
How do I resolve this issue. Any help is greatly appreciated.

Below you can see the error and the code segment.

Thanks
Kohila Gnanaratne

Here is the error I get when stdout is tied to tk widow using ( tie *STDOUT, 'Tk::Text', $t;)

Tk::Error: Can't locate auto/Tk/Text/CLOSE.al in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Tk/Derived.pm line 469
 Carp::croak at /usr/lib/perl5/5.8.8/Carp.pm line 269
 AutoLoader::AUTOLOAD at /usr/lib/perl5/5.8.8/AutoLoader.pm line 112
Tk::Derived::Delegate at /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Tk/Derived.pm line 469 Tk::Widget::__ANON__ at /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Tk/Widget.pm line 322
 Expect::spawn at /usr/lib/perl5/vendor_perl/5.8.8/Expect.pm line 163
 main::doInstallation at ./xx.pl line 61
 Tk callback for .frame.button
Tk::__ANON__ at /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Tk.pm line 247 Tk::Button::butUp at /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Tk/Button.pm line 111
 <ButtonRelease-1>
 (command bound to event)
X Error of failed request:  BadGC (invalid GC parameter)
  Major opcode of failed request:  60 (X_FreeGC)
  Resource id in failed request:  0x6000028
  Serial number of failed request:  768
  Current serial number in output stream:  567



Here is the code of the program:
#!/usr/bin/perl  -w - for linux with debugging on

use Shell qw(uname pwd);
use Tk;
use Expect;
#use strict;
require Tk::Dialog;
require Tk::Radiobutton;

$Expect::Exp_Internal=0;
$Expect::Log_Stdout=1;

my $sftpusr="muser";
my $sftppswd="mpswd";
my $timeout=5;

my $location="";
my $lab;

my @labName = ();
@labSet = (
        [ "", "", "", 0],
        [ "m5", "192.168.200.14", "41", 1],
        );
#######################################################################
$mw = MainWindow->new(-title => "LOGVIEW");
$ft = $mw->Frame->pack(-side => 'top', -fill => 'x');
$fb = $mw->Frame->pack(-side => 'bottom', -fill => 'x');

foreach (@labSet) { push( @labName, $_->[0]); }
$ft->Label(-text => "Lab Name:")->pack(-side =>'left', -anchor => 'w' );
my $opt = $ft -> Optionmenu(-options =>\@labName,
-command => \&displayLoads, -variable => \$location, -relief => 'sunken')->pack(-side =>'left', -anchor => 'w'); $fb->Button(-text => "Exit", -command => sub{exit;})->pack( -side => 'right'); $ft->Button(-text => "Display", -command => \&displayInfo )->pack( -side => 'right');

$t = $mw->Scrolled("Text")->pack(-side => 'left', -fill => 'x', -expand => 1);

$ssh = new Expect;

# forever loop
MainLoop;
##################################################################################################

sub displayLoads {
        foreach( @labSet) {
                if (  $_->[0] eq $location ) { $lab = $_; last; }
        }
}sub  displayInfo {

        tie *STDOUT, 'Tk::Text', $t;

        my $parms=sprintf("%s@%s", ${sftpusr}, $lab->[1]);
        print "**** pram $parms\n";

        $ssh->spawn("ssh", $parms) or die "Cannot ssh to $lab->[1]\n";
        $ssh->expect( $timeout,
        #       ["Password Authentication"],
["Are you sure you want to continue connecting (yes/no)?", sub { my $self = shift; $self->send("yes\n"); exp_continue;} ], [".*password: ", sub { my $self = shift; $self->send("$sftppswd\n"); exp_continue; } ], [ 'timeout', sub { print "Error ssh login timeout\n"; exit} ],
                [".*-root>"],
                );

        # check board type
$ssh->send( "cat \/proc\/cpuinfo | grep platform | awk \'{print \$3}\'\n");
        $ssh->expect( $timeout,
["XXXX", sub { my $self = shift; print "\n*** FAILED: Target board is not p$lab->[2] cpu **\n"; $self->soft_close(); exit(); } ],
#               [".*-root>"] ,
[ 'timeout', sub { print "Error ssh cmd cpuinfo timeout\n"; exit(); } ]
             );
}






Reply via email to