Unix and Linux Discussions Tagged with expect |
|
Thread / Thread Starter |
Last Post |
Replies |
Views |
Forum |
|
|
|
0 |
22,425 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
5,773 |
UNIX for Beginners Questions & Answers |
|
|
|
3 |
10,034 |
Shell Programming and Scripting |
|
|
|
3 |
6,832 |
Shell Programming and Scripting |
|
|
|
2 |
4,104 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
8,220 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
1,944 |
UNIX for Beginners Questions & Answers |
|
|
|
7 |
2,147 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
1,505 |
UNIX for Beginners Questions & Answers |
|
|
|
3 |
4,280 |
Shell Programming and Scripting |
|
|
|
2 |
1,569 |
UNIX for Beginners Questions & Answers |
|
|
|
6 |
4,483 |
Shell Programming and Scripting |
|
|
|
1 |
5,024 |
Ubuntu |
|
|
|
0 |
7,041 |
Shell Programming and Scripting |
|
|
|
0 |
3,756 |
Shell Programming and Scripting |
|
|
|
2 |
7,000 |
Shell Programming and Scripting |
|
|
|
2 |
2,888 |
Shell Programming and Scripting |
|
|
|
7 |
7,587 |
Shell Programming and Scripting |
|
|
|
1 |
5,812 |
Shell Programming and Scripting |
|
|
|
5 |
4,245 |
Shell Programming and Scripting |
|
|
|
0 |
1,815 |
Shell Programming and Scripting |
|
|
|
0 |
3,882 |
Programming |
|
|
|
7 |
3,981 |
Shell Programming and Scripting |
|
|
|
2 |
29,980 |
Shell Programming and Scripting |
|
|
|
0 |
2,193 |
Shell Programming and Scripting |
|
|
|
2 |
8,417 |
Shell Programming and Scripting |
|
|
|
1 |
6,830 |
Shell Programming and Scripting |
|
|
|
3 |
8,818 |
UNIX for Advanced & Expert Users |
|
|
|
1 |
3,129 |
Shell Programming and Scripting |
|
|
|
2 |
8,656 |
Shell Programming and Scripting |
|
|
|
6 |
21,198 |
Shell Programming and Scripting |
|
|
|
5 |
10,904 |
Shell Programming and Scripting |
|
|
|
1 |
2,355 |
UNIX for Dummies Questions & Answers |
|
|
|
1 |
4,333 |
Shell Programming and Scripting |
|
|
|
0 |
3,562 |
Shell Programming and Scripting |
|
|
|
0 |
2,567 |
Shell Programming and Scripting |
|
|
|
3 |
8,585 |
Shell Programming and Scripting |
|
|
|
1 |
2,397 |
Shell Programming and Scripting |
|
|
|
5 |
6,299 |
Shell Programming and Scripting |
|
|
|
3 |
16,745 |
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)