php-doc-en/reference/expect/functions/expect-expectl.xml
2011-08-25 21:09:23 +00:00

206 lines
6.1 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml: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 <acronym>EOF</acronym> is seen
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>int</type><methodname>expect_expectl</methodname>
<methodparam><type>resource</type><parameter>expect</parameter></methodparam>
<methodparam><type>array</type><parameter>cases</parameter></methodparam>
<methodparam choice="opt"><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 <acronym>EOF</acronym> 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="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>0.2.1</entry>
<entry>
Prior to version 0.2.1, in <parameter>match</parameter> parameter a match string was returned,
not an array of match substrings.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</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(pattern, value to return if pattern matched)
array("password:", "asked for password"),
array("yes/no)?", "asked for yes/no")
);
while (true) {
switch (expect_expectl($stream, $cases)) {
case "asked for password":
fwrite($stream, "my password\n");
break;
case "asked for yes/no":
fwrite($stream, "yes\n");
break;
case EXP_TIMEOUT:
case EXP_EOF:
break 2; // break both the switch statement and the while loop
default:
die "Error has occurred!";
}
}
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:"~/.phpdoc/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
-->