Unix and Linux Discussions Tagged with expect |
|
Thread / Thread Starter |
Last Post |
Replies |
Views |
Forum |
|
|
|
0 |
24,514 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
6,437 |
UNIX for Beginners Questions & Answers |
|
|
|
3 |
10,543 |
Shell Programming and Scripting |
|
|
|
3 |
7,133 |
Shell Programming and Scripting |
|
|
|
2 |
4,928 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
8,778 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
2,456 |
UNIX for Beginners Questions & Answers |
|
|
|
7 |
2,882 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
1,752 |
UNIX for Beginners Questions & Answers |
|
|
|
3 |
4,605 |
Shell Programming and Scripting |
|
|
|
2 |
1,819 |
UNIX for Beginners Questions & Answers |
|
|
|
6 |
5,262 |
Shell Programming and Scripting |
|
|
|
1 |
5,532 |
Ubuntu |
|
|
|
0 |
7,566 |
Shell Programming and Scripting |
|
|
|
0 |
4,390 |
Shell Programming and Scripting |
|
|
|
2 |
7,427 |
Shell Programming and Scripting |
|
|
|
2 |
3,088 |
Shell Programming and Scripting |
|
|
|
7 |
8,081 |
Shell Programming and Scripting |
|
|
|
1 |
6,186 |
Shell Programming and Scripting |
|
|
|
5 |
4,489 |
Shell Programming and Scripting |
|
|
|
0 |
2,005 |
Shell Programming and Scripting |
|
|
|
0 |
4,913 |
Programming |
|
|
|
7 |
4,297 |
Shell Programming and Scripting |
|
|
|
2 |
30,794 |
Shell Programming and Scripting |
|
|
|
0 |
2,409 |
Shell Programming and Scripting |
|
|
|
2 |
8,829 |
Shell Programming and Scripting |
|
|
|
1 |
7,492 |
Shell Programming and Scripting |
|
|
|
3 |
9,329 |
UNIX for Advanced & Expert Users |
|
|
|
1 |
3,422 |
Shell Programming and Scripting |
|
|
|
2 |
8,994 |
Shell Programming and Scripting |
|
|
|
6 |
21,623 |
Shell Programming and Scripting |
|
|
|
5 |
11,212 |
Shell Programming and Scripting |
|
|
|
1 |
2,565 |
UNIX for Dummies Questions & Answers |
|
|
|
1 |
4,551 |
Shell Programming and Scripting |
|
|
|
0 |
3,778 |
Shell Programming and Scripting |
|
|
|
0 |
2,813 |
Shell Programming and Scripting |
|
|
|
3 |
9,168 |
Shell Programming and Scripting |
|
|
|
1 |
2,541 |
Shell Programming and Scripting |
|
|
|
5 |
6,672 |
Shell Programming and Scripting |
|
|
|
3 |
17,394 |
UNIX for Dummies Questions & Answers |
EXPECT_EXPECTL(3) 1 EXPECT_EXPECTL(3)
expect_expectl - Waits until the output from a process matches one of the patterns, a specified time period has passed, or anEOFis seen
SYNOPSIS
int expect_expectl (resource $expect, array $cases, [array &$match])
DESCRIPTION
Waits until the output from a process matches one of the patterns, a specified time period has passed, or an EOF is seen.
If $match is provided, then it is filled with the result of search. The matched string can be found in $match[0]. The match substrings
(according to the parentheses) in the original pattern can be found in $match[1], $match[2], and so on, up to $match[9] (the limitation of
libexpect).
PARAMETERS
o $expect
- An Expect stream, previously opened with expect_popen(3).
o $cases
- An array of expect cases. Each expect case is an indexed array, as described in the following table:
Expect Case Array
+----------+--------------------------+---+---+---+
|Index Key | | | | |
| | | | | |
| | Value Type | | | |
| | | | | |
| | Description | | | |
| | | | | |
| | Is Mandatory | | | |
| | | | | |
| | Default Value | | | |
| | | | | |
+----------+--------------------------+---+---+---+
| 0 | | | | |
| | | | | |
| | string | | | |
| | | | | |
| | pattern, that will be | | | |
| | matched against the out- | | | |
| | put from the stream | | | |
| | | | | |
| | yes | | | |
| | | | | |
| | | | | |
| | T{ 1 | | | |
| | | | | |
| | mixed | | | |
| | | | | |
| | value, that will be | | | |
| | returned by this func- | | | |
| | tion, if the pattern | | | |
| | matches | | | |
| | | | | |
| | yes | | | |
| | | | | |
| | | | | |
| | T{ 2 | | | |
| | | | | |
| | integer | | | |
| | | | | |
| | pattern type, one of: | | | |
| | EXP_GLOB, EXP_EXACT or | | | |
| | EXP_REGEXP | | | |
| | | | | |
| | no | | | |
| | | | | |
| | | | | |
| | EXP_GLOB | | | |
| | | | | |
+----------+--------------------------+---+---+---+
RETURN VALUES
Returns value associated with the pattern that was matched.
On failure this function returns: EXP_EOF, EXP_TIMEOUT or EXP_FULLBUFFER
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 0.2.1 | |
| | |
| | Prior to version 0.2.1, in $match parameter a |
| | match string was returned, not an array of match |
| | substrings. |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
expect_expectl(3) example
<?php
// Copies file from remote host:
ini_set("expect.timeout", 30);
$stream = fopen("expect://scp user@remotehost:/var/log/messages /home/user/messages.txt", "r");
$cases = array(
// array(pattern, value to return if pattern matched)
array("password:", "asked for password"),
array("yes/no)?", "asked for yes/no")
);
while (true) {
switch (expect_expectl($stream, $cases)) {
case "asked for password":
fwrite($stream, "my password
");
break;
case "asked for yes/no":
fwrite($stream, "yes
");
break;
case EXP_TIMEOUT:
case EXP_EOF:
break 2; // break both the switch statement and the while loop
default:
die "Error has occurred!";
}
}
fclose($stream);
?>
SEE ALSO
expect_popen(3).
PHP Documentation Group EXPECT_EXPECTL(3)