Unix and Linux Discussions Tagged with expect |
|
Thread / Thread Starter |
Last Post |
Replies |
Views |
Forum |
|
|
|
0 |
20,030 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
4,948 |
UNIX for Beginners Questions & Answers |
|
|
|
3 |
8,625 |
Shell Programming and Scripting |
|
|
|
3 |
5,635 |
Shell Programming and Scripting |
|
|
|
2 |
2,895 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
7,764 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
1,393 |
UNIX for Beginners Questions & Answers |
|
|
|
7 |
1,618 |
UNIX for Beginners Questions & Answers |
|
|
|
1 |
1,078 |
UNIX for Beginners Questions & Answers |
|
|
|
3 |
3,743 |
Shell Programming and Scripting |
|
|
|
2 |
1,181 |
UNIX for Beginners Questions & Answers |
|
|
|
6 |
3,746 |
Shell Programming and Scripting |
|
|
|
1 |
4,006 |
Ubuntu |
|
|
|
0 |
6,425 |
Shell Programming and Scripting |
|
|
|
0 |
3,327 |
Shell Programming and Scripting |
|
|
|
2 |
6,694 |
Shell Programming and Scripting |
|
|
|
2 |
2,674 |
Shell Programming and Scripting |
|
|
|
7 |
7,041 |
Shell Programming and Scripting |
|
|
|
1 |
5,397 |
Shell Programming and Scripting |
|
|
|
5 |
4,083 |
Shell Programming and Scripting |
|
|
|
0 |
1,645 |
Shell Programming and Scripting |
|
|
|
0 |
3,265 |
Programming |
|
|
|
7 |
3,648 |
Shell Programming and Scripting |
|
|
|
2 |
29,094 |
Shell Programming and Scripting |
|
|
|
0 |
1,998 |
Shell Programming and Scripting |
|
|
|
2 |
7,953 |
Shell Programming and Scripting |
|
|
|
1 |
6,079 |
Shell Programming and Scripting |
|
|
|
3 |
8,345 |
UNIX for Advanced & Expert Users |
|
|
|
1 |
2,900 |
Shell Programming and Scripting |
|
|
|
2 |
8,383 |
Shell Programming and Scripting |
|
|
|
6 |
20,813 |
Shell Programming and Scripting |
|
|
|
5 |
10,436 |
Shell Programming and Scripting |
|
|
|
1 |
2,158 |
UNIX for Dummies Questions & Answers |
|
|
|
1 |
4,061 |
Shell Programming and Scripting |
|
|
|
0 |
3,327 |
Shell Programming and Scripting |
|
|
|
0 |
2,350 |
Shell Programming and Scripting |
|
|
|
3 |
8,084 |
Shell Programming and Scripting |
|
|
|
1 |
2,247 |
Shell Programming and Scripting |
|
|
|
5 |
5,109 |
Shell Programming and Scripting |
|
|
|
3 |
16,112 |
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)