Web lists-archives.com

Re: [PHP] expect_expectl: how to show the part of the stream that itis matching against




On 3-8-2015 22:35, jm+php-general@xxxxxxx wrote:
     switch (expect_expectl($stream, $cases, $match)) {
       // for some reason, this case has to be first....
       case 'BUFFER':
   echo "\n\n ______________________ BUFFERING ____________________ \n\n";
         $buffer .= $match[1];
         $break;

This is a variable, not a statement.


       // Note: We don't have to check any specific precondition
       // Having the prompt is precondition enough to continue working
       case 'PROMPT':
   echo "\n\n _____________________ FOUND PROMPT __________________ \n\n";
         $buffer .= $match[0];
.........

---------- END CODE --------

I must say that doesn't work either in my case. It matches the BUFFER
case once, and then goes to PROMPT, even if there was no prompt that I
could see.

Basically I'd like to be able to process each line of the stream
regardless if it matches the prompt or not.

Well that's completely expected. The reason for it is simply that you're not breaking out of the switch at the end of your first case. This means that after finishing the BUFFER case, the process automatically continues on until either it finds a break statement, or the end of the switch.

Some code to help explain:
switch($foo) {
   case 'a':
echo 'we found a. but since there is no break here, we continue to b';
   case 'b':
echo 'we found b. Or maybe we found a and the code passed on to the code for b... who knows?';
      break; // we quit the switch now!
   case 'c':
echo 'we found c and are 100% sure it IS c, since if it were a or b it would have broken out of the switch earlier';
}

So the solution is simple for you, add a break statement. Not $break, since that's a variable, but break (the keyword).

- Tul

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php