Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Telnet I/O with Perl/Tk
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Matt  
View profile  
 More options Mar 1 2011, 2:04 am
Newsgroups: comp.lang.perl.tk
From: Matt <lord.of.the.d...@gmail.com>
Date: Mon, 28 Feb 2011 23:04:44 -0800 (PST)
Local: Tues, Mar 1 2011 2:04 am
Subject: Telnet I/O with Perl/Tk
Hi guys,

Wondering if someone might be able to give me some help, I have a
simple Perl program to control a telnet session, using Net::Telnet  I
would like to have I/O redirected to a Tk GUI, but am a little
confused about how to this.  I have the Tk GUI written, just confused
about what type of widget I should use in the GUI and how to get the
Input and Output from my terminal to the gui.

Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
$Bill  
View profile  
 More options Mar 1 2011, 7:11 pm
Newsgroups: comp.lang.perl.tk
From: "$Bill" <n...@SPAMOLAtodbe.com>
Date: Tue, 01 Mar 2011 16:11:49 -0800
Local: Tues, Mar 1 2011 7:11 pm
Subject: Re: Telnet I/O with Perl/Tk
On 2/28/2011 11:04 PM, Matt wrote:

> Hi guys,

> Wondering if someone might be able to give me some help, I have a
> simple Perl program to control a telnet session, using Net::Telnet  I
> would like to have I/O redirected to a Tk GUI, but am a little
> confused about how to this.  I have the Tk GUI written, just confused
> about what type of widget I should use in the GUI and how to get the
> Input and Output from my terminal to the gui.

I'm just guessing here, but I think I'd just use a scrolled list box
( $listBox = ??->Scrolled('Listbox', ... ) and feed the output of you
$telnet->cmd call returns into the box (possibly interspersed with the
commands you sent (possibly with different markings or colors to denote
cmds from replies) using a $ListBox->insert('end', ... ).  Hope that
makes sense.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jack  
View profile  
 More options Mar 1 2011, 11:34 pm
Newsgroups: comp.lang.perl.tk
From: Jack <goodca...@hotmail.com>
Date: Tue, 01 Mar 2011 21:34:24 -0700
Local: Tues, Mar 1 2011 11:34 pm
Subject: Re: Telnet I/O with Perl/Tk
On 01/03/2011 5:11 PM, $Bill wrote:

Another option is to dump the output to a Text widget.

Opt 1) I have never used Net::Telnet before - but it seems you should be
able to capture the output and "manually" write it to the text widget.
The drawback is that this would one way - writing.

Opt 2) You didn't mention your platform - but if it is NOT windows AND
you are willing to forego Net::Telnet, then you can also try launching a
telnet session using IPC::Open2 and use fileevent to trigger the writing
to the Text widget.This would also allow input to be read if you trigger
reading from the text widget (trigger on hitting the Enter key). This
should offer you two way input/output.

http://perlmonks.org/?node_id=452894

Opt 3) Embed an actual xterm into a Tk window (Frame) using the
-container option and the xterm -into option. The last time I tried to
do this was a number of years ago and I didn't like how it remained a
fixed size. This way you can type your commands in to an actual terminal
window.

Jack


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt  
View profile  
 More options Mar 3 2011, 11:44 am
Newsgroups: comp.lang.perl.tk
From: Matt <lord.of.the.d...@gmail.com>
Date: Thu, 3 Mar 2011 08:44:53 -0800 (PST)
Local: Thurs, Mar 3 2011 11:44 am
Subject: Re: Telnet I/O with Perl/Tk
On Mar 1, 11:34 pm, Jack <goodca...@hotmail.com> wrote:

Hi,

Thanks very much for the help-I decided to experiment with embedding
the xterm in the Tk window.  This worked, but I am using Tk::NoteBook
and it seems that the SAME xterm process gets embedded in each tab of
the NoteBook.  Is there a way to insert a different xterm process into
each page of the notebook?

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve C  
View profile  
 More options Mar 3 2011, 3:23 pm
Newsgroups: comp.lang.perl.tk
From: Steve C <smallp...@juno.com>
Date: Thu, 03 Mar 2011 15:23:58 -0500
Local: Thurs, Mar 3 2011 3:23 pm
Subject: Re: Telnet I/O with Perl/Tk
On 03/03/2011 11:44 AM, Matt wrote:

Barring a cosmic shift in reality, Tk::Notebook is doing what your
program tells it to.  Post some code and let's see.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt  
View profile  
 More options Mar 3 2011, 4:27 pm
Newsgroups: comp.lang.perl.tk
From: Matt <lord.of.the.d...@gmail.com>
Date: Thu, 3 Mar 2011 13:27:41 -0800 (PST)
Local: Thurs, Mar 3 2011 4:27 pm
Subject: Re: Telnet I/O with Perl/Tk
On Mar 3, 3:23 pm, Steve C <smallp...@juno.com> wrote:

Ah yes, sorry.

#$mw is the main window variable
#@hosts is the array contain each host to telnet to.

my $canv = $mw->Canvas(-bg => 'lightsteelblue',
     -relief => 'sunken',
     -width => 800,
     -height => 600)->pack(-expand => 1, -fill => 'both');

my $xtermWidth = 400;
my $xtermHeight = 300;

my $book = $canv->NoteBook()->pack(-fill=>'both', -expand=>1);

for my $host (@hosts) {
my $tab = $book->add ("$host", -label => $host, -createcmd=>sub
{ create($host) });

}

MainLoop;

sub create {
my $host = shift;

#This code from perlmonks on embedding xterm windows:

        ## this Frame is needed for including the xterm in Tk::Canvas
        my $xtermContainer = $canv->Frame(-container => 1);
        my $xtid = $xtermContainer->id();
        # converting the id from HEX to decimal as xterm requires a
decimal Id
        +
        my ($xtId) = sprintf hex $xtid;

        my $dcontitem = $canv->createWindow(275,175,
        -window => $xtermContainer,
        -width => $xtermWidth+100,
        -height => $xtermHeight,
        -state => 'normal');
        system("xterm -into $xtId -hold -e \'telnet $host; bash\' &");

}

I have tried changing the value of $xtId to try and force it to
recognize multiple sessions, but that prevents the terminal window
from being created at all.  Am I perhaps missing something in the
NoteBook tab generation to recognize multiple xterms?

Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jack  
View profile  
 More options Mar 3 2011, 8:51 pm
Newsgroups: comp.lang.perl.tk
From: Jack <goodca...@hotmail.com>
Date: Thu, 03 Mar 2011 18:51:51 -0700
Local: Thurs, Mar 3 2011 8:51 pm
Subject: Re: Telnet I/O with Perl/Tk

I see the problem right away. You are packing a Frame into a "window"
into a canvas. And you are doing the same thing in the same place for
each of your hosts.

I think you really want to pack the xterm into each frame of the
Notebook right? Remember that when you "add" a page in a Notebook it
returns a Tk::Frame. I believe though that the -container option *must*
be specified at creation. (i.e. You cannot configure it afterwards
according to the documentation for Tk::Frame). I am not sure if the
"add" method will support this. Typically any extra options will be
passed to the base widget. If not - then you can just as easily pack
another frame into each page of the notebook using the -container option
- then use *that* winID in your xterm command.

I'm on windows right now - but I'll log into work to see if I can come
up with some working code using a linux machine.

Stay tuned - unless someone (even yourself) beats me to it ;)

Jack


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jack  
View profile  
 More options Mar 3 2011, 10:19 pm
Newsgroups: comp.lang.perl.tk
From: Jack <goodca...@hotmail.com>
Date: Thu, 03 Mar 2011 20:19:24 -0700
Local: Thurs, Mar 3 2011 10:19 pm
Subject: Re: Telnet I/O with Perl/Tk
On 03/03/2011 6:51 PM, Jack wrote:

Okay here is a working example:

#!/usr/bin/perl -w

use strict;
use Tk;
use Tk::NoteBook;
my %page;

my $mw = tkinit;
my $nb = $mw->NoteBook()->pack(-expand=>1, -fill=>'both');

foreach my $page (1..4) {
   $page{$page} = $nb->add("page$page", -label=>"Session $page");
   doXterm($page{$page});

}

MainLoop;

sub doXterm {
   my ($pageframe) = @_;

   my $intframe = $pageframe->Frame(
     -container=>1,
     -width=>600,
     -height=>400)->pack(-expand=>0, -fill=>'both');
   my $ID = $intframe->id();
   my ($hexID) = sprintf hex $ID;

   system("xterm -into $hexID -geometry 100x40 -hold &"); #geom colsxrows

}

__END__

I have left the "telnet" stuff up to you.

Jack


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »