Cannot get telnet session output using TK

PC platform Windows XP
Perl 5.8.7 ActiveState

I am trying to get my TK GUI to print output from a device via telnet.  However, I get the following output on the application...

Entered loginG6, IP address is 10.2.161.209.
Net::Telnet=GLOB(0x1eacbdc)
Net::Telnet=GLOB(0x1eacbdc)
blah is 1
Entered command show ver all
Net::Telnet=GLOB(0x1eacbdc)

Entire Code....

#!c:\perl\bin\perl.exe
use Tk;

my $mw = new MainWindow(-title=>"G6 Telnet");; # Main Window
my $frm_name = $mw -> Frame();
my $lab = $frm_name -> Label(-text=>"SCM IP Address:");
my $ent = $frm_name -> Entry();

my $frm_name2 = $mw -> Frame();
my $lab2 = $frm_name2 -> Label(-text=>"SCM Command:");
my $ent2 = $frm_name2 -> Entry();

my $but = $mw -> Button(-text=>"Push Me", -command =>\&loginG6);

my $textarea = $mw -> Frame(); #Creating Another Frame
my $txt = $textarea -> Text(-width=>40, -height=>10);
my $srl_y = $textarea -> Scrollbar(-orient=>'v',-command=>[yview => $txt]);
my $srl_x = $textarea -> Scrollbar(-orient=>'h',-command=>[xview => $txt]);
$txt -> configure(-yscrollcommand=>['set', $srl_y],
            -xscrollcommand=>['set',$srl_x]);

$lab -> grid(-row=>1,-column=>1);
$ent -> grid(-row=>1,-column=>2);
$frm_name -> grid(-row=>1,-column=>1,-columnspan=>2);
$lab2 -> grid(-row=>2,-column=>1);
$ent2 -> grid(-row=>2,-column=>2);
$frm_name2 -> grid(-row=>2,-column=>1,-columnspan=>2);

$but -> grid(-row=>4,-column=>1,-columnspan=>2);

$txt -> grid(-row=>1,-column=>1);
$srl_y -> grid(-row=>1,-column=>2,-sticky=>"ns");
$srl_x -> grid(-row=>2,-column=>1,-sticky=>"ew");
$textarea -> grid(-row=>5,-column=>1,-columnspan=>2);

MainLoop;


  #-------------------------------------------------------------------
  # Subroutine: loginG6
  # Version Added: 1.0
  # Input: n/a
  # Output:
  # Description:
  #-------------------------------------------------------------------

sub loginG6 {
             use Net::Telnet;
             use Socket;
             $tn = new Net::Telnet ( Timeout=>10,
                                           Errmode=> sub {&noconn;});
           my $scmip = $ent -> get();
           my $cmd = $ent2 -> get();

           $txt -> insert('end',"Entered loginG6, IP address is $scmip.\n"); # this prints correctly "Entered loginG6, IP address is 10.2.161.209."
             $tn->open($scmip);
             $tn->waitfor('/Login[: ]$/i');
             $txt -> insert('end',"$tn\n");  # this prints incorrectly "Net::Telnet=GLOB(0x1ead070)"
             $tn->print("****");
             $tn->waitfor('/Password[: ]*$/i');
             $txt -> insert('end',"$tn\n");  # this prints incorrectly "Net::Telnet=GLOB(0x1ead070)"
             $tn->print("****");
             $blah=$tn->waitfor('/.+/i');
             $txt -> insert('end',"blah is $blah\n");  # this prints incorrectly "blah is 1"
             autoAnswer("set cli more off");
#             $tn->waitfor('/CLI/i');
#             $txt -> insert('end',"$tn");
             autoAnswer("set ev di all on");
#             $tn->waitfor('/CLI/i');
#             $txt -> insert('end',"$tn");
             autoAnswer("set al di on");
#             $tn->waitfor('/CLI/i');
#             $txt -> insert('end',"$tn");
             $tn->print($cmd);
             $tn->waitfor('/.+/i');
            $txt -> insert('end',"Entered command $cmd\n"); # this prints correctly "Entered command show ver all"
             $txt -> insert('end',"$tn\n");  # this prints incorrectly "Net::Telnet=GLOB(0x1ead070)"
            
}

  #-------------------------------------------------------------------
  # Subroutine: noconn
  # Version Added: 1.0
  # Input: n/a
  # Output:
  # Description: Reports to user that no connection was made to device
  #-------------------------------------------------------------------

sub noconn {
      print "\n";
      print "##################################################################\n";
      print "ERROR\n";
      print "Cannot connect to devise at $scmip.  What is up with that?.\n";
      print "##################################################################\n";
      exit;
}

  #-------------------------------------------------------------------
  # Subroutine: autoAnswer
  # Version Added: 1.0
  # Input: n/a
  # Output:
  # Description:
  #-------------------------------------------------------------------

    sub autoAnswer  {
#    print "hitting autoanswer with, $cliCmd<br>";
      my ($cliCmd) = @_;
#      print "$cliCmd<br>";
      $tn->print($cliCmd);
      $line = " ";
      while ($line !~ /Command Completed/) {
         if ($line =~ /you sure/) {
           $tn->print ("y");
         }
         $line = $tn->getline();
      }
    }
lormandAsked:
Who is Participating?
 
clockwatcherConnect With a Mentor Commented:
Pretty sure the methods return a list:

  @blah = $tn->waitfor('/.+/i');
  $txt -> insert('end',"blah is ".join("",@blah)."\n");

or

  $txt -> insert('end', "blah is ".join("", $tn->waitfor('.+/i'))."\n");

0
 
Perl_DiverCommented:
where you say prints incrrectly:

$txt -> insert('end',"$tn\n");  # this prints incorrectly "Net::Telnet=GLOB(0x1ead070)"
$txt -> insert('end',"$tn\n");  # this prints incorrectly "Net::Telnet=GLOB(0x1ead070)"

what do you think or expect should be printed there? $tn is a reference to the Net::Telnet object you created, thats all you are printing, the value of the reference. Maybe you should be assigning the return value to a scalar, for example:

$open = $tn->open($scmip);

and then:

$txt -> insert('end',"$open\n");  # this prints incorrectly "Net::Telnet=GLOB(0x1ead070)"

or whatever is appropriate for what you want to print at that point in the script.
0
 
lormandAuthor Commented:
In my script, I assign a scalar to the telnet object as you suggest.

Example below from above script...

$blah=$tn->waitfor('/.+/i');
$txt -> insert('end',"blah is $blah\n");

In this case, I get "blah is 1".

I attempted to print "$tn" in the TK object, because when I use it in an ordinary command line perl script, it prints every character returned up to the regex.  

For example,

print  $tn->waitfor('/CLI/i');

when using in CGI or CLI will print to console all characters until reaching "CLI".  But assigning it to a scalar and printing to TK GUI shows "1".
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.