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 commented

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.

Thanks

Kmg

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

!/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( -si +de => 'right'); $t = $mw->Scrolled("Text")->pack(-side => 'left', -fill => 'x', -expan +d => 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 \'{prin +t \$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 timeou +t\n"; exit(); } ] ); }

In reply to Use of perl_expect in TK gui session by kmg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.