From: Ken I. <fn...@ua...> - 2007-07-26 16:53:11
|
On Thu, Jul 26, 2007 at 11:08:11AM -0400, Chuck Son wrote: > It appears that whenever I use send(), the next expect() will read the > previous line again and thus causing the send() to occur twice. I read > the FAQ and it appears this is a common problem? Has anyone figured out > a workaround? Thanks. Not sure I understand the question, but maybe you're referring to the just-sent string appearing in the response? That would be the "echo" from the application, which is normal for interactive applications. If you're driving the application manually, each character you see in response to what you type is coming back from the application, not from your local terminal. When automating this, you just need to expect to see the same string (usually) just sent, usually with the end-of-line character(s) changed ("foo\r" is sent, "foo\n" or "foo\r\n" is seen in response). The echo might be considered a confirmation that the app has gotten the right command, or an indication of the state of the application. The command's response should immediately follow the echo. > my $exp = new Expect; > $exp->raw_pty(1); > $exp->spawn("randomApplication.pl"); > > while ($value != 3) { > my $value = $exp->expect($timeout, > [ qr/sender/], > [ qr/receiver/], > [ qr/whatever/] > ); > > if ($value == 1) { > $exp-send("Yes"); > } > elsif ($value == 2) { > $exp-send("No"); > } > } Or maybe you meant something else... I don't follow what the code snippet is intended to demonstrate/illustrate. Ken -- Ken Irving, fn...@ua... |