<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.expect.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'es',
  ),
  'this' => 
  array (
    0 => 'function.expect-expectl.php',
    1 => 'expect_expectl',
    2 => 'Espera a que la salida de un proceso coincida con un patr&oacute;n,
   se supere un determinado periodo de tiempo, o se alcance un EOF',
  ),
  'up' => 
  array (
    0 => 'ref.expect.php',
    1 => 'Funciones de Expect',
  ),
  'prev' => 
  array (
    0 => 'ref.expect.php',
    1 => 'Funciones de Expect',
  ),
  'next' => 
  array (
    0 => 'function.expect-popen.php',
    1 => 'expect_popen',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'es',
    'path' => 'reference/expect/functions/expect-expectl.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.expect-expectl" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">expect_expectl</h1>
  <p class="verinfo">(PECL expect &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">expect_expectl</span> &mdash; <span class="dc-title">Espera a que la salida de un proceso coincida con un patrón,
   se supere un determinado periodo de tiempo, o se alcance un <abbr title="End Of File">EOF</abbr>
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.expect-expectl-description">
  <h3 class="title">Descripción</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>expect_expectl</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$expect</code></span>, <span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$cases</code></span>, <span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter reference">&$match</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="simpara">
   Espera a que la salida de un proceso coincida con un patrón, se supere un determinado
   periodo de tiempo, o se alcance un <abbr title="End Of File">EOF</abbr>.
  </p>
  <p class="simpara">
   Si se proporciona el parámetro <code class="parameter">match</code>, se le asignará el resultado de la
   búsqueda. La cadena que coincide se encuentra en <code class="parameter">match[0]</code>.
   Las subcadenas que coincidan (de acuerdo a los paréntesis) con el patrón original se encuentran
   en <code class="parameter">match[1]</code>, <code class="parameter">match[2]</code>, y así
   hasta <code class="parameter">match[9]</code> (límite establecido por libexpect).
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.expect-expectl-parameters">
  <h3 class="title">Parámetros</h3>
  <dl>
   
    <dt><code class="parameter">expect</code></dt>
    <dd>
     <span class="simpara">
      Flujo de Expect, abierto anteriormente con
      <span class="function"><a href="function.expect-popen.php" class="function">expect_popen()</a></span>.
     </span>
    </dd>
   
   
    <dt><code class="parameter">cases</code></dt>
    <dd>
     <p class="para">
      Matriz con casos de expect. Cada caso será un array indexado, tal
      como se describe en la siguiente tabla:
      <table class="doctable table">
       <caption><strong>Array de Caso de Expect</strong></caption>
       
        <thead>
         <tr>
          <th>Clave de índice</th>
          <th>Tipo de valor</th>
          <th>Descripción</th>
          <th>Es Obligatorio</th>
          <th>Valor por omisión</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>0</td>
          <td>string</td>
          <td>patrón, que buscará coincidencias en la salida del flujo</td>
          <td>sí</td>
          <td class="empty">&nbsp;</td>
         </tr>

         <tr>
          <td>1</td>
          <td>mixto</td>
          <td>valor, que devolverá esta función, si coincidiera el patrón</td>
          <td>sí</td>
          <td class="empty">&nbsp;</td>
         </tr>

         <tr>
          <td>2</td>
          <td>integer</td>
          <td>
           tipo de patrón, de entre:
           <a href="expect.constants.php#constant.exp-glob" class="link"><strong><code><a href="expect.constants.php#constant.exp-glob">EXP_GLOB</a></code></strong></a>,
           <a href="expect.constants.php#constant.exp-exact" class="link"><strong><code><a href="expect.constants.php#constant.exp-exact">EXP_EXACT</a></code></strong></a>
           o
           <a href="expect.constants.php#constant.exp-regexp" class="link"><strong><code><a href="expect.constants.php#constant.exp-regexp">EXP_REGEXP</a></code></strong></a>
          </td>
          <td>no</td>
          <td><a href="expect.constants.php#constant.exp-glob" class="link"><strong><code><a href="expect.constants.php#constant.exp-glob">EXP_GLOB</a></code></strong></a></td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>
   
  </dl>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.expect-expectl-returnvalues">
  <h3 class="title">Valores devueltos</h3>
  <p class="simpara">
   Devuelve valores asociados con el patrón que coincida.
  </p>
  <p class="simpara">
   En caso de error esta función devuelve:
   <a href="expect.constants.php#constant.exp-eof" class="link"><strong><code><a href="expect.constants.php#constant.exp-eof">EXP_EOF</a></code></strong></a>,
   <a href="expect.constants.php#constant.exp-timeout" class="link"><strong><code><a href="expect.constants.php#constant.exp-timeout">EXP_TIMEOUT</a></code></strong></a>
   o
   <a href="expect.constants.php#constant.exp-fullbuffer" class="link"><strong><code><a href="expect.constants.php#constant.exp-fullbuffer">EXP_FULLBUFFER</a></code></strong></a>
  </p>
 </div>

 <div class="refsect1 changelog" id="refsect1-function.expect-expectl-changelog">
  <h3 class="title">Historial de cambios</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versión</th>
      <th>Descripción</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>PECL expect 0.2.1</td>
      <td>
       Antes de la versión 0.2.1, en el parámetro <code class="parameter">match</code> se devolvía el string que
       coincidiera, no un array de substrings coincidentes.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 <div class="refsect1 examples" id="refsect1-function.expect-expectl-examples">
  <h3 class="title">Ejemplos</h3>
  <div class="example" id="example-1">
   <p><strong>Ejemplo #1 Ejemplo de <span class="function"><strong>expect_expectl()</strong></span></strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Copias de los archivos de host remoto:<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">"expect.timeout"</span><span style="color: #007700">, </span><span style="color: #0000BB">30</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stream </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"expect://scp user@remotehost:/var/log/messages /home/user/messages.txt"</span><span style="color: #007700">, </span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$cases </span><span style="color: #007700">= array(<br />    </span><span style="color: #FF8000">// array(patrón, valor que se devolverá si el patrón es encontrado)<br />    </span><span style="color: #007700">array(</span><span style="color: #DD0000">"password:"</span><span style="color: #007700">, </span><span style="color: #DD0000">"asked for password"</span><span style="color: #007700">),<br />    array(</span><span style="color: #DD0000">"yes/no)?"</span><span style="color: #007700">,  </span><span style="color: #DD0000">"asked for yes/no"</span><span style="color: #007700">)<br />);<br /><br />while (</span><span style="color: #0000BB">true</span><span style="color: #007700">) {<br />    switch (</span><span style="color: #0000BB">expect_expectl</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">, </span><span style="color: #0000BB">$cases</span><span style="color: #007700">)) {<br />        case </span><span style="color: #DD0000">"asked for password"</span><span style="color: #007700">:<br />            </span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">, </span><span style="color: #DD0000">"my password\n"</span><span style="color: #007700">);<br />            break;<br />        case </span><span style="color: #DD0000">"asked for yes/no"</span><span style="color: #007700">:<br />            </span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">, </span><span style="color: #DD0000">"yes\n"</span><span style="color: #007700">);<br />            break;<br />        case </span><span style="color: #0000BB">EXP_TIMEOUT</span><span style="color: #007700">:<br />        case </span><span style="color: #0000BB">EXP_EOF</span><span style="color: #007700">:<br />            break </span><span style="color: #0000BB">2</span><span style="color: #007700">; </span><span style="color: #FF8000">// break tanto la sentencia switch y el bucle while<br />        </span><span style="color: #007700">default:<br />            die(</span><span style="color: #DD0000">"Error has occurred!"</span><span style="color: #007700">);<br />    }<br />}<br /><br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.expect-expectl-seealso">
  <h3 class="title">Ver también</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.expect-popen.php" class="function" rel="rdfs-seeAlso">expect_popen()</a> - Ejecuta comandos por la shell Bourne, y abre el flujo PTY
   al proceso</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>