XXXV. Expect Functions
This extension allows to interact with processes through PTY. You may
consider using the expect://
wrapper with the filesystem
functions which provide a simpler and more intuitive interface.
This module uses the functions of the expect library.
You need libexpect version >= 5.43.0.
Diese PECL Erweiterung
ist nicht Teil von PHP.
Zusätzliche Informationen, wie neue Releases, Downloads
Quelldateien, Maintainerinformation und ein CHANGELOG finden Sie hier:
http://pecl.php.net/package/expect.
Für PHP 4 finden Sie die Quellen dieser
PECL Erweiterung im ext/ Verzeichnis
innerhalb der PHP Quellen oder unter dem PECL Link wie
oben angegeben.
In order to use these functions you must compile PHP with expect support
by using the --with-expect[=DIR]
configure option.
Windows users will enable php_expect.dll inside
of php.ini in order to use these functions.
Für PHP 4 finden Sie die DLL im
extensions/ Verzeichnis der PHP Windows Binärdistribution.
Sie können die DLL für
diese PECL Erweiterung entweder von
PHP Downloads oder von
http://snaps.php.net/ herunterladen.
Das Verhalten dieser Funktionen wird
durch Einstellungen in der php.ini beeinflusst.
In order to configure expect extension, there are configuration options
in the configuration file php.ini.
Tabelle 1. Expect Konfigurationsoptionen | Name | Standard | Veränderbar | Changelog |
|---|
| expect.timeout | "10" | PHP_INI_ALL | | | expect.loguser | "1" | PHP_INI_ALL | | | expect.logfile | "" | PHP_INI_ALL | |
For further details and definitions of the
PHP_INI_* constants, see the Anhang G.
Hier eine kurze Erklärung der
Konfigurationsoptionen:
- expect.timeout
integer
The timeout period for waiting for the data, when using the
expect_expectl() function.
A value of "-1" disables a timeout from occurring.
Anmerkung:
A value of "0" causes the expect_expectl()
function to return immediately.
- expect.loguser
boolean
Whether expect should send any output from the spawned process to stdout.
Since interactive programs typically echo their input, this usually suffices
to show both sides of the conversation.
- expect.logfile
string
Name of the file, where the output from the spawned process will be
written. If this file doesn't exist, it will be created.
Anmerkung:
If this configuration is not empty, the output is written regardless of
the value of expect.loguser.
Diese Erweiterung definiert keine Resource-Typen. Folgende Konstanten werden von dieser
Erweiterung definiert und stehen nur zur Verfügung, wenn die Erweiterung entweder
statisch in PHP kompiliert oder dynamisch zur Laufzeit geladen wurde.
This example connects to the remote host via SSH, and prints the remote
uptime.
Beispiel 1. Expect Usage Example |
<?php
ini_set ("expect.loguser", "Off");
$stream = fopen ("expect://ssh root@remotehost uptime", "r");
$cases = array (
array (0 => "password:", 1 => PASSWORD)
);
switch (expect_expectl ($stream, $cases))
{
case PASSWORD:
fwrite ($stream, "password\n");
break;
default:
die ("Error was occurred while connecting to the remote host!\n");
}
while ($line = fgets ($stream)) {
print $line;
}
fclose ($stream);
?>
|
|
- Inhaltsverzeichnis
- expect_expectl -- Waits until the output from a process matches one
of the patterns, a specified time period has passed, or an EOF is seen
- expect_popen -- Exectute command via Bourne shell, and open the PTY stream to
the process
|