From: Robin L. P. <rlp...@di...> - 2010-12-07 18:30:10
|
On Tue, Dec 07, 2010 at 01:45:28PM +0100, Ismaël BALLO wrote: > > Hi, > > I'm new to Expect.pm, I've written a piece of code : I started > with one that works but I want to add some complexity I want to > use a loop in case the first password is not good : > > I'm connecting from a first machine (pivot) then ssh a second > machine to do $cmd on a third machine > > Questions : > > 1/ Is it possible to use named sub inside expects ( I didn't see > examples ..) ? Right near the top of the man page: # or multi-match on several spawned commands with callbacks, # just like the Tcl version $exp->expect($timeout, [ qr/regex1/ => sub { my $exp = shift; $exp->send("response\n"); exp_continue; } ], [ "regexp2" , \&callback, @cbparms ], ); \&callback is a reference to a function. > 2/ What do I miss to make this piece of code works ? How is it failing? Can you turn on debug(2) and post the results? What did the simple version that worked look like? Also, I'd suggest seperating out the subroutines, for readability. -Robin -- http://singinst.org/ : Our last, best hope for a fantastic future. Lojban (http://www.lojban.org/): The language in which "this parrot is dead" is "ti poi spitaki cu morsi", but "this sentence is false" is "na nei". My personal page: http://www.digitalkingdom.org/rlp/ |