Unix and Linux Discussions Tagged with expect |
|
Thread / Thread Starter |
Last Post |
Replies |
Views |
Forum |
|
|
|
0 |
24,457 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
6,422 |
UNIX for Beginners Questions & Answers |
|
|
|
3 |
10,531 |
Shell Programming and Scripting |
|
|
|
3 |
7,130 |
Shell Programming and Scripting |
|
|
|
2 |
4,901 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
8,764 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
2,449 |
UNIX for Beginners Questions & Answers |
|
|
|
7 |
2,874 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
1,740 |
UNIX for Beginners Questions & Answers |
|
|
|
3 |
4,595 |
Shell Programming and Scripting |
|
|
|
2 |
1,814 |
UNIX for Beginners Questions & Answers |
|
|
|
6 |
5,256 |
Shell Programming and Scripting |
|
|
|
1 |
5,524 |
Ubuntu |
|
|
|
0 |
7,560 |
Shell Programming and Scripting |
|
|
|
0 |
4,384 |
Shell Programming and Scripting |
|
|
|
2 |
7,426 |
Shell Programming and Scripting |
|
|
|
2 |
3,086 |
Shell Programming and Scripting |
|
|
|
7 |
8,080 |
Shell Programming and Scripting |
|
|
|
1 |
6,185 |
Shell Programming and Scripting |
|
|
|
5 |
4,486 |
Shell Programming and Scripting |
|
|
|
0 |
2,005 |
Shell Programming and Scripting |
|
|
|
0 |
4,889 |
Programming |
|
|
|
7 |
4,295 |
Shell Programming and Scripting |
|
|
|
2 |
30,794 |
Shell Programming and Scripting |
|
|
|
0 |
2,409 |
Shell Programming and Scripting |
|
|
|
2 |
8,820 |
Shell Programming and Scripting |
|
|
|
1 |
7,490 |
Shell Programming and Scripting |
|
|
|
3 |
9,325 |
UNIX for Advanced & Expert Users |
|
|
|
1 |
3,416 |
Shell Programming and Scripting |
|
|
|
2 |
8,993 |
Shell Programming and Scripting |
|
|
|
6 |
21,620 |
Shell Programming and Scripting |
|
|
|
5 |
11,210 |
Shell Programming and Scripting |
|
|
|
1 |
2,557 |
UNIX for Dummies Questions & Answers |
|
|
|
1 |
4,548 |
Shell Programming and Scripting |
|
|
|
0 |
3,778 |
Shell Programming and Scripting |
|
|
|
0 |
2,811 |
Shell Programming and Scripting |
|
|
|
3 |
9,167 |
Shell Programming and Scripting |
|
|
|
1 |
2,538 |
Shell Programming and Scripting |
|
|
|
5 |
6,668 |
Shell Programming and Scripting |
|
|
|
3 |
17,381 |
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)