From: Matt Z. <mzagrabe@d.umn.edu> - 2007-03-22 18:26:55
|
> The reason I am concerned with using Net::Telnet with Expect is I have > designed my program to be multithreaded and from what I read Net::Telnet > is thread safe whereas IO-Tty is not. >=20 > The symptoms of what happens when using Expect and Net::Telnet to telnet > to a 1924 is this: >=20 > telnet negotiation (non printable characters) happens and then it looks > like no other traffic is sent from the remote side. I am currently > combing through tcpdump and wireshark analysis of this, but I thought I > would send an email to the list to see if anyone had any ideas in the > meantime. Solved... All thanks goes to Bryan Bueter who did all the leg-work on this one. As he said (off list), Net::Telnet needed to be coaxed into getting past the telnet handshaking and negotiations, then it could be passed to Expect. The important line to note below is the 'waitfor'. Then it is safe to hand the file handle over to Expect. Working code follows: #!/usr/bin/perl use strict; use Expect; use Net::Telnet (); print "\n\n-----------START OF Expect with Net::Telnet-----------\n"; my $e =3D new Net::Telnet(); $e->open("c1924.domain.org"); my @lines =3D $e->waitfor('/User Interface Menu/'); my $exp =3D Expect->exp_init($e); $exp->log_stdout(1); &expect_selection($exp); $exp->expect(5,'-re','>\z'); $exp->hard_close(); print "\n\n-----------END OF Expect with Net::Telnet-----------\n"; sub expect_selection { my $exp =3D shift; $exp->expect(5, [ qr/Selection.*/, sub { my $fh =3D shift; $fh->send('k'); undef; } ]); } --=20 Matt Zagrabelny - mzagrabe@d.umn.edu - (218) 726 8844 University of Minnesota Duluth Information Technology Systems & Services PGP key 1024D/84E22DA2 2005-11-07 Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 He is not a fool who gives up what he cannot keep to gain what he cannot lose. -Jim Elliot |