|
XXXIV. 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.
本 PECL 增加未綁定於 PHP 中。
進一步訊息例如新版本,下載,源程式,維護者訊息以及更新日誌可以在此找到:
http://pecl.php.net/package/expect.
在 PHP 4 中本 PECL 增加的源程式位於
PHP 源程式中的 ext/ 目錄下或是在上面的
PECL 連線中。
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.
在 PHP 4 中本 DLL 位於
PHP Windows 執行包中的 extensions/ 目錄下。
可以從 PHP
下載頁面或是 http://snaps.php.net/
下載此 PECL 增加的
DLL 檔案。
這些函數的行為受 php.ini 的影響。
In order to configure expect extension, there are configuration options
in the configuration file php.ini.
表格 1. Expect 配置選項 名字 | 預設 | 可修改範圍 | Changelog |
---|
expect.timeout | "10" | PHP_INI_ALL | | expect.loguser | "On" | PHP_INI_ALL | | expect.logfile | "" | PHP_INI_ALL | |
有關 PHP_INI_* 常量進一步的細節與定義參見 附錄 G。
以下是配置選項的簡要解釋。
- 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.
- 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.
注:
If this configuration is not empty, the output is written regardless of
the value of expect.loguser.
以下常量由本增加模組定義,因此只有在本增加模組被編譯到
PHP 中,或是在運行時被動態加載後才有效。
This example connects to the remote host via SSH, and prints the remote
uptime.
例子 1. Expect Usage Example
<?php ini_set ("expect.loguser", "Off");
$stream = popen ("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); ?>
|
|
- 目錄
- 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
| |