I've got a working version. I'm still not clear on what I did with this that was different from the original, but I went back and wrote it from scratch (I didn't mention that I started with a version that almost worked, then stopped). I didn't copy or paste ANYTHING from the original, I started without sub routines and wrote a simple test, then broke it down into subroutines and got it working. I'll be looking through my old code to see the mistakes once I get time. Here's the working version:

#!/usr/bin/perl use Expect; our $abi; setup(); sendcmd(); sub setup { $cmd = "telnet wogglebug"; $abi = Expect->new(); $abi->spawn($cmd); $res = $abi->expect(5, "/ #", "not known"); print "Result: $res\n"; if ($res != 1) { print "Failure to open process.\n"; exit; } $before = $abi->before(); show("Before", $before); $after = $abi->after(); show("After", $after); $abi->clear_accum(); return; } sub sendcmd { $abi->send("ls\n"); # print $abi "ls\n"; $before = $abi->before(); $after = $abi->after(); $res = $abi->expect(10, "/ #"); show("Before command", $before); show("After command", $after); show("Result", $res); return; } sub show { my ($msg, $data) = @_; print "-----------------------\n$msg: $data\n--------------------- +--\n"; return; }

Thanks for the help and when I see what it was that messed up the first version, I'll post it.


In reply to Re: Expect Issues by HalNineThousand
in thread Expect Issues by HalNineThousand

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.