<?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 => 'pt_BR',
  ),
  'this' => 
  array (
    0 => 'function.expect-expectl.php',
    1 => 'expect_expectl',
    2 => 'Espera at&eacute; que a sa&iacute;da de um processo corresponda a um
  dos padr&otilde;es, um per&iacute;odo de tempo especificado tenha passado ou um EOF seja alcan&ccedil;ado',
  ),
  'up' => 
  array (
    0 => 'ref.expect.php',
    1 => 'Fun&ccedil;&otilde;es de Expect',
  ),
  'prev' => 
  array (
    0 => 'ref.expect.php',
    1 => 'Fun&ccedil;&otilde;es de Expect',
  ),
  'next' => 
  array (
    0 => 'function.expect-popen.php',
    1 => 'expect_popen',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'pt_BR',
    '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 até que a saída de um processo corresponda a um
  dos padrões, um período de tempo especificado tenha passado ou um <abbr title="End Of File">EOF</abbr> seja alcançado
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.expect-expectl-description">
  <h3 class="title">Descrição</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 até que a saída de um processo corresponda a um dos padrões,
   um período de tempo especificado tenha passado ou um <abbr title="End Of File">EOF</abbr> seja alcançado.
  </p>
  <p class="simpara">
   Se <code class="parameter">match</code> for fornecido, então ele será preenchido com o resultado da pesquisa.
   A string correspondente pode ser encontrada em <code class="parameter">match[0]</code>.
   As substrings de correspondência (de acordo com os parênteses) no padrão original podem ser encontradas
   em <code class="parameter">match[1]</code>, <code class="parameter">match[2]</code> e assim por
   diante, até <code class="parameter">match[9]</code> (a limitação do 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">
      Um fluxo Expect, previamente aberto com
      <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">
      Um array de casos Expect. Cada caso é um array indexado,
      como descrito na tabela a seguir:
      <table class="doctable table">
       <caption><strong>Array de Casos Expect</strong></caption>
       
        <thead>
         <tr>
          <th>Chave do Índice</th>
          <th>Tipo do Valor</th>
          <th>Descrição</th>
          <th>Mandatório</th>
          <th>Valor Padrão</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>0</td>
          <td>string</td>
          <td>padrão que será comparado com a saída do fluxo</td>
          <td>sim</td>
          <td class="empty">&nbsp;</td>
         </tr>

         <tr>
          <td>1</td>
          <td>mixed</td>
          <td>valor que será retornado por esta função se o padrão for correspondido</td>
          <td>sim</td>
          <td class="empty">&nbsp;</td>
         </tr>

         <tr>
          <td>2</td>
          <td>inteiro</td>
          <td>
           tipo do padrão, uma das opções:
           <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>
           ou
           <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>não</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">Valor Retornado</h3>
  <p class="simpara">
   Retorna o valor associado com o padrão que foi correspondido.
  </p>
  <p class="simpara">
   Em caso de falha, esta função retorna:
   <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>
   ou
   <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">Registro de Alterações</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versão</th>
      <th>Descrição</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>PECL expect 0.2.1</td>
      <td>
      Antes da versão 0.2.1, uma string de correspondência era retornada no parâmetro <code class="parameter">match</code>,
      e não um array de substrings correspondidas.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 <div class="refsect1 examples" id="refsect1-function.expect-expectl-examples">
  <h3 class="title">Exemplos</h3>
  <div class="example" id="example-1">
   <p><strong>Exemplo #1 Exemplo 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">// Copia arquivo do servidor 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(padrão, valor a retornar se houver correspondência)<br />    </span><span style="color: #007700">array(</span><span style="color: #DD0000">"senha:"</span><span style="color: #007700">, </span><span style="color: #DD0000">"pediu senha"</span><span style="color: #007700">),<br />    array(</span><span style="color: #DD0000">"sim/não)?"</span><span style="color: #007700">,  </span><span style="color: #DD0000">"perguntou sim ou não"</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">"pediu senha"</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">"minha senha\n"</span><span style="color: #007700">);<br />            break;<br />        case </span><span style="color: #DD0000">"perguntou sim ou não"</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">"sim\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">// sai do switch e do while<br />        </span><span style="color: #007700">default:<br />            die(</span><span style="color: #DD0000">"Ocorreu um erro!"</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">Veja Também</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.expect-popen.php" class="function" rel="rdfs-seeAlso">expect_popen()</a> - Executa comando via Bourne shell, e abre o fluxo PTY para
  o processo</span></li>
  </ul>
 </div>

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