TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:10172] Perl newbie - starting a telnet process...



I doug around and found this in an email bag:

===========
From: daily_perl@yoak.com
Subject: Daily Perl FAQ - How can I write expect in Perl?

This is a daily mailing from the Perl FAQ a Day website.
For subscription info, or to have your address removed from 
the mailing list, please see http://yoak.com/daily_perl/
-- 

Question:
How can I write expect in Perl?

    Once upon a time, there was a library called chat2.pl (part of the
    standard perl distribution), which never really got finished. If
    you find it somewhere, *don't use it*. These days, your best bet is
    to look at the Expect module available from CPAN, which also
    requires two other modules from CPAN, IO::Pty and IO::Stty.


-- 
The contents of this message are part of the Perl FAQ:
Please note that "I" below refers to FAQ authors, and *not* Jeff Yoak or
Perl FAQ a Day.

Where to get this document [the Perl FAQ]
   This document is posted regularly to comp.lang.perl.announce and
   several other related newsgroups. It is available in a variety of
   formats from CPAN in the /CPAN/doc/FAQs/FAQ/ directory, or on the web
   at http://www.perl.com/perl/faq/ .

CREDITS
   When I first began the Perl FAQ in the late 80s, I never realized it
   would have grown to over a hundred pages, nor that Perl would ever
   become so popular and widespread. This document could not have been
   written without the tremendous help provided by Larry Wall and the
   rest of the Perl Porters.

AUTHOR AND COPYRIGHT INFORMATION
   Copyright (c) 1997 Tom Christiansen and Nathan Torkington. All rights
   reserved.
===========

Clay Fandre wrote:
> 
> Troy Johnson wrote:
> >
> > Is there an expect perl package on CPAN somewhere?
> 
> As far as I know there isn't such a package. (yet). Expect is TCL based
> and very different that perl. What I have done in the past is to call
> small expect scripts from my 'main' perl scripts. I get the best of both
> worlds.
> 
> >
> > Clay Fandre wrote:
> > >
> > > I would recommend using expect. It is easier to use (in this particular
> > > case) and is much nicer about timeouts and stuff like that. It also
> > > comes with autoexpect, which automatically creates an expect script for
> > > you. Very nice.
> > >
> > > As far as your perl script goes, you are grabbing the output of the
> > > telnet command instead of inputting to it. To input, the pipe goes after
> > > the command:
> > > open( TELNETPROC, "telnet|") || die "Unable to open telnet $!\n";
> > >
> > > (do a perldoc -f open for more info)
> > >
> > > open only allows for one way or the other. (Input or output.) That's why
> > > I recommend expect. If you really need to use perl, look at open2, which
> > > allows for 2-way communication to your process. (I'm not sure if it is
> > > installed by default. Might have to install it from CPAN.)
> > >
> > > Mike Glaser wrote:
> > > >
> > > > I was trying to write a Perl script today that would telnet into a
> > > > router, issue a few commands and then close. I wasn't having any
> > > > luck. Can anyone tell me how to go about doing it?? Here are the
> > > > particulars...
> > > >
> > > > 1) telnet
> > > > 2) open xxx.xxx.xxx.xxx
> > > > 3) enter_password
> > > > 4) command
> > > > 5) exit
> > > >
> > > > Here is what my script was looking like...
> > > >
> > > > #!/usr/bin/perl
> > > > open( TELNETPROC, "|telnet");
> > > > print TELNETPROC "open 192.168.0.1\n";
> > > > print TELNETPROC "thesecretpassword\n";
> > > > print TELNETPROC "clear line 1\n";
> > > > print TELNETPROC "exit\n";
> > > > close FTPPROC;
> > > >
> > > > What may I be missing here?? I have the O'Reilly book 'Learing Perl'
> > > > to help me get started with Perl, but I have not been able to pick up
> > > > much yet.
> > > >
> > > > Thanks,
> > > > Mike Glaser
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: tclug-list-unsubscribe@mn-linux.org
> > > > For additional commands, e-mail: tclug-list-help@mn-linux.org
> > >
> > > --
> > > Clay Fandre
> > > cfandre@maddog.mn-linux.org
> > > Twin Cities Linux Users Group
> > > http://www.mn-linux.org
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tclug-list-unsubscribe@mn-linux.org
> > > For additional commands, e-mail: tclug-list-help@mn-linux.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tclug-list-unsubscribe@mn-linux.org
> > For additional commands, e-mail: tclug-list-help@mn-linux.org
> 
> --
> Clay Fandre
> cfandre@maddog.mn-linux.org
> Twin Cities Linux Users Group
> http://www.mn-linux.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tclug-list-unsubscribe@mn-linux.org
> For additional commands, e-mail: tclug-list-help@mn-linux.org