From: Bala A. <ba...@sb...> - 2004-07-13 02:23:47
|
Expect doesn't have a blocking mode or concept. Except gets chunks from the kernel buffer and it isn't always keeping up with the interacting program. That is, expect is usually behind and the application it is interacting with is usually ahead. To sync up both, (to block like you alluded to) , you need to loop on the pattern you are looking for. You need to consume all the patterns that are available on the stdout, produced either by you "sending" them or produced by the application. If you pass up any input, then your expect program may appear to work, but not consistently. Take ls \n for example. You need to loop looking for the command to return to unix prompt such $ or # or > or what have you. While waiting - you should consume everything that comes your way by using expect(3,'-re', "(.*?)\n") (note .*? won't consume \n thus you have hard code \n. Every time you consume you should put that out to a buffer such as $buffer .= $obj->match() ; Sometimes you may have to use expect_before() but you have to play with it to see what suits your response best. I will be happy to post some samples if you need more help. Good luck expecting. B Ayres --- ex...@th... wrote: > I'm trying to write a script in perl, using the > expect.pm module, which will > connect via ssh to a remote system and run a series > of commands. I can connect > and run commands, but am having trouble with the > interactive aspects of the script. > > I need to check the status of the system and make > calls accordingly, but cannot > find a way to make "blocking" calls (expect, wait, > send) or catch the return > value (e.g. send ("ls\n") and catch the results). > > Could you folks provide me with sample code or links > to documentation that could > help with this? I've read through the man, er > perldoc, page and could not find > solutions there. > > thanks, > Andrew > ex...@th... > > > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & > Training. > Attend Black Hat Briefings & Training, Las Vegas > July 24-29 - > digital self defense, top technical experts, no > vendor pitches, > unmatched networking opportunities. Visit > www.blackhat.com > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |