PHP ��U
前一頁 |  | 下一頁

# 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.

# �ݨD

This module uses the functions of the expect library. You need libexpect version >= 5.43.0.

# �w��

This PECL extension is not bundled with PHP. Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: http://pecl.php.net/package/expect.

In PHP 4 this PECL extensions source can be found in the `ext/` directory within the PHP source or at the PECL link above. 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. In PHP 4 this DLL resides in the `extensions/` directory within the PHP Windows binaries download. You may download this PECL extension DLL from the PHP Downloads page or at http://snaps.php.net/.

# ���ɴ�պA

`php.ini`�]�w�|�v�T�o�Ǩ�ƪ�欰�C

In order to configure expect extension, there are configuration options in the configuration file `php.ini`.

表格 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 |

For further details and definitions of the PHP_INI_* constants, see the 附錄 G.

�o�̬�²�u�c��O��C

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.

  > 注: 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.

  > 注: If this configuration is not empty, the output is written regardless of the value of expect.loguser.

# �귽��

�o�ө��S�w�q���귽�C

# �w��w�q�`��

�H�U�`�ƥѦ��w�q�A�u�b�o�ө��Q�sĶ�PHP�ι��ɴ�Q�ʺA��J�ɦ�ġC

`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.

# �d��

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 = 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);
?>`

前一頁 | 內容 | 下一頁
read_exif_data | 上一層 | expect_expectl