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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |