XXXIV. Expect Functions
Introducción
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.
Requisitos
This module uses the functions of the expect library. You need libexpect version >= 5.43.0.
Instalación
Esta extension PECL no esta ligada a PHP. Mas informacion sobre nuevos lanzamientos, descargas ficheros de fuentes, informacion sobre los responsables asi como un 'CHANGELOG', se puede encontrar aqui: http://pecl.php.net/package/expect.
En PHP 4 la fuente de las extensiones PECL pueden encontrarse en el directorio ext/ que se existe en las fuentes de PHP o en el enlace PECL de arriba. 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. En PHP 4, esta DLL se encuentra en el directorio extensions/ que existe en los binarios de PHP para Windows. Podeis descargar esta DLL de las extensiones PECL desde la pagina PHP Downloads o desde http://snaps.php.net/.
Configuración en tiempo de ejecución
El comportamiento de estas funciones está afectado por los valores definidos en php.ini.
In order to configure expect extension, there are configuration options in the configuration file php.ini.
Tabla 1. Expect Configure Options
| Name | Default | Changeable | Changelog |
|---|---|---|---|
| expect.timeout | "10" | PHP_INI_ALL | |
| expect.loguser | "1" | PHP_INI_ALL | |
| expect.logfile | "" | PHP_INI_ALL |
A continuación se presenta una corta explicación de las directivas de configuración.
- 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.
Nota: 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.
Nota: If this configuration is not empty, the output is written regardless of the value of expect.loguser.
Tipos de recursos
Esta extensión no tiene ningún tipo de recurso definido.
Constantes predefinidas
Estas constantes están definidas por esta extensión y estarán disponibles solamente cuando la extensión ha sido o bien compilada dentro de PHP o grabada dinámicamente en tiempo de ejecución.
- EXP_GLOB (integer)
Indicates that the pattern is a glob-style string pattern.
- EXP_EXACT (integer)
Indicates that the pattern is an exact string.
- EXP_REGEXP (integer)
Indicates that the pattern is a regexp-style string pattern.
- EXP_EOF (integer)
Value, returned by expect_expectl(), when EOF is reached.
- EXP_TIMEOUT (integer)
Value, returned by expect_expectl() upon timeout of seconds, specified in value of expect.timeout
- EXP_FULLBUFFER (integer)
Value, returned by expect_expectl() if no pattern have been matched.
Ejemplos
This example connects to the remote host via SSH, and prints the remote uptime.
- Tabla de contenidos
- 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
