Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 2798

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Waits until the output from a process matches one
  of the patterns, a specified time period has passed, or an EOF is seen</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.expect.html">Expect Functions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.expect-popen.html">expect_popen</a></div>
 <div class="up"><a href="ref.expect.html">Expect Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><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">Waits until the output from a process matches one
  of the patterns, a specified time period has passed, or an <acronym title="End Of File">EOF</acronym> is seen
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.expect-expectl-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><strong>expect_expectl</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$expect</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$cases</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$match</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   Waits until the output from a process matches one of the patterns,
   a specified time period has passed, or an <acronym title="End Of File">EOF</acronym> is seen.
  </p>
  <p class="para">
   If <em><code class="parameter">match</code></em> is provided, then it is filled with the result of search.
   The matched string can be found in <em><code class="parameter">match[0]</code></em>.
   The match substrings (according to the parentheses) in the original pattern can be found
   in <em><code class="parameter">match[1]</code></em>, <em><code class="parameter">match[2]</code></em>, and so
   on, up to <em><code class="parameter">match[9]</code></em> (the limitation of libexpect).
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.expect-expectl-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">expect</code></em></span>
     <dd>

      <p class="para">
       An Expect stream, previously opened with
        <span class="function"><a href="function.expect-popen.html" class="function">expect_popen()</a></span>.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">cases</code></em></span>
     <dd>

      <p class="para">
       An array of expect cases. Each expect case is an indexed array,
       as described in the following table:
       <table class="doctable table">
        <caption><strong>Expect Case Array</strong></caption>
        
         <thead>
          <tr>
           <th>Index Key</th>
           <th>Value Type</th>
           <th>Description</th>
           <th>Is Mandatory</th>
           <th>Default Value</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td>0</td>
           <td>string</td>
           <td>pattern, that will be matched against the output from the stream</td>
           <td>yes</td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td>1</td>
           <td>mixed</td>
           <td>value, that will be returned by this function, if the pattern matches</td>
           <td>yes</td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td>2</td>
           <td>integer</td>
           <td>
            pattern type, one of:
            <a href="expect.constants.html#constants.expect.exp-glob" class="link"><strong><code>EXP_GLOB</code></strong></a>,
            <a href="expect.constants.html#constants.expect.exp-exact" class="link"><strong><code>EXP_EXACT</code></strong></a>
            or
            <a href="expect.constants.html#constants.expect.exp-regexp" class="link"><strong><code>EXP_REGEXP</code></strong></a>
           </td>
           <td>no</td>
           <td><a href="expect.constants.html#constants.expect.exp-glob" class="link"><strong><code>EXP_GLOB</code></strong></a></td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.expect-expectl-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns value associated with the pattern that was matched.
  </p>
  <p class="para">
   On failure this function returns:
   <a href="expect.constants.html#constants.expect.exp-eof" class="link"><strong><code>EXP_EOF</code></strong></a>,
   <a href="expect.constants.html#constants.expect.exp-timeout" class="link"><strong><code>EXP_TIMEOUT</code></strong></a>
   or
   <a href="expect.constants.html#constants.expect.exp-fullbuffer" class="link"><strong><code>EXP_FULLBUFFER</code></strong></a>
  </p>
 </div>

 <div class="refsect1 changelog" id="refsect1-function.expect-expectl-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>0.2.1</td>
       <td>
       Prior to version 0.2.1, in <em><code class="parameter">match</code></em> parameter a match string was returned,
       not an array of match substrings.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.expect-expectl-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-3638">
    <p><strong>Example #1  <span class="function"><strong>expect_expectl()</strong></span> example</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">//&nbsp;Copies&nbsp;file&nbsp;from&nbsp;remote&nbsp;host:<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">,&nbsp;</span><span style="color: #0000BB">30</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stream&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"expect://scp&nbsp;user@remotehost:/var/log/messages&nbsp;/home/user/messages.txt"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$cases&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;array(pattern,&nbsp;value&nbsp;to&nbsp;return&nbsp;if&nbsp;pattern&nbsp;matched)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">array(</span><span style="color: #DD0000">"password:"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"asked&nbsp;for&nbsp;password"</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">"yes/no)?"</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #DD0000">"asked&nbsp;for&nbsp;yes/no"</span><span style="color: #007700">)<br />);<br /><br />while&nbsp;(</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;switch&nbsp;(</span><span style="color: #0000BB">expect_expectl</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$cases</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #DD0000">"asked&nbsp;for&nbsp;password"</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my&nbsp;password\n"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #DD0000">"asked&nbsp;for&nbsp;yes/no"</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"yes\n"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">EXP_TIMEOUT</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">EXP_EOF</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;break&nbsp;both&nbsp;the&nbsp;switch&nbsp;statement&nbsp;and&nbsp;the&nbsp;while&nbsp;loop<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">default:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die&nbsp;</span><span style="color: #DD0000">"Error&nbsp;has&nbsp;occurred!"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<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>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.expect-expectl-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.expect-popen.html" class="function" rel="rdfs-seeAlso">expect_popen()</a> - Execute command via Bourne shell, and open the PTY stream to
  the process</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.expect.html">Expect Functions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.expect-popen.html">expect_popen</a></div>
 <div class="up"><a href="ref.expect.html">Expect Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>