php-doc-en/reference/expect/functions/expect-expectl.xml
2006-07-04 08:26:08 +00:00

185 lines
5.2 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<refentry id="function.expect-expectl">
<refnamediv>
<refname>expect_expectl</refname>
<refpurpose>Waits until the output from a process matches one
of the patterns, a specified time period has passed, or an EOF is seen
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>mixed</type><methodname>expect_expectl</methodname>
<methodparam><type>resource</type><parameter>expect</parameter></methodparam>
<methodparam><type>array</type><parameter>cases</parameter></methodparam>
<methodparam><type>array</type><parameter role="reference">match</parameter></methodparam>
</methodsynopsis>
<para>
Waits until the output from a process matches one of the patterns,
a specified time period has passed, or an EOF is seen.
</para>
<para>
If <parameter>match</parameter> is provided, then it is filled with the result of search.
The matched string can be found in <parameter>match[0]</parameter>.
The match substrings (according to the parentheses) in the original pattern can be found
in <parameter>match[1]</parameter>, <parameter>match[2]</parameter>, and so
on, up to <parameter>match[9]</parameter> (the limitation of libexpect).
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>expect</parameter></term>
<listitem>
<para>
An Expect stream, previously opened with
<function>expect_popen</function>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>cases</parameter></term>
<listitem>
<para>
An array of expect cases. Each expect case is an indexed array,
as described in the following table:
<table>
<title>Expect Case Array</title>
<tgroup cols="5">
<thead>
<row>
<entry>Index Key</entry>
<entry>Value Type</entry>
<entry>Description</entry>
<entry>Is Mandatory</entry>
<entry>Default Value</entry>
</row>
</thead>
<tbody>
<row>
<entry>0</entry>
<entry>string</entry>
<entry>pattern, that will be matched against the output from the stream</entry>
<entry>yes</entry>
<entry></entry>
</row>
<row>
<entry>1</entry>
<entry>mixed</entry>
<entry>value, that will be returned by this function, if the pattern matches</entry>
<entry>yes</entry>
<entry></entry>
</row>
<row>
<entry>2</entry>
<entry>integer</entry>
<entry>
pattern type, one of:
<link linkend="constants.expect.exp_glob"><constant>EXP_GLOB</constant></link>,
<link linkend="constants.expect.exp_exact"><constant>EXP_EXACT</constant></link>
or
<link linkend="constants.expect.exp_regexp"><constant>EXP_REGEXP</constant></link>
</entry>
<entry>no</entry>
<entry><link linkend="constants.expect.exp_glob"><constant>EXP_GLOB</constant></link></entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns value associated with the pattern that was matched.
</para>
<para>
On failure this function returns:
<link linkend="constants.expect.exp_eof"><constant>EXP_EOF</constant></link>,
<link linkend="constants.expect.exp_timeout"><constant>EXP_TIMEOUT</constant></link>
or
<link linkend="constants.expect.exp_fullbuffer"><constant>EXP_FULLBUFFER</constant></link>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>expect_expectl</function> example</title>
<programlisting role="php">
<![CDATA[
<?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 (0 => "password:", 1 => PASSWORD),
array (0 => "yes/no)?", 1 => YESNO)
);
while (true) {
switch (expect_expectl ($stream, $cases))
{
case PASSWORD:
fwrite ($stream, "password\n");
break;
case YESNO:
fwrite ($stream, "yes\n");
break;
case EXP_TIMEOUT:
case EXP_EOF:
break 2;
default:
die ("Error has occurred!\n");
}
}
fclose ($stream);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>expect_popen</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->