<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.expect-expectl.php',
    1 => 'expect_expectl',
    2 => 'プロセスの出力がパターンに一致する・指定した時間が経過する・
  あるいは EOF に達するのいずれかにあてはまるまで待ち続ける',
  ),
  'up' => 
  array (
    0 => 'ref.expect.php',
    1 => 'Expect 関数',
  ),
  'prev' => 
  array (
    0 => 'ref.expect.php',
    1 => 'Expect 関数',
  ),
  'next' => 
  array (
    0 => 'function.expect-popen.php',
    1 => 'expect_popen',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    '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">プロセスの出力がパターンに一致する・指定した時間が経過する・
  あるいは <abbr title="End Of File">EOF</abbr> に達するのいずれかにあてはまるまで待ち続ける
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.expect-expectl-description">
  <h3 class="title">説明</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">
   プロセスの出力がパターンに一致する・指定した時間が経過する・
   あるいは <abbr title="End Of File">EOF</abbr> に達するのいずれかにあてはまるまで待ち続けます。
  </p>
  <p class="simpara">
   <code class="parameter">match</code>
   を指定すると、検索結果がそこに保存されます。
   一致した文字列が <code class="parameter">match[0]</code> に保存され、
   元のパターンの中の (括弧で囲まれた) 部分に一致する文字列が
   <code class="parameter">match[1]</code>、<code class="parameter">match[2]</code>、
   と順に、最大 <code class="parameter">match[9]</code> まで
   (libexpect の制限です) 保存されます。
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.expect-expectl-parameters">
  <h3 class="title">パラメータ</h3>
  <dl>
   
    <dt><code class="parameter">expect</code></dt>
    <dd>
     <span class="simpara">
      事前に <span class="function"><a href="function.expect-popen.php" class="function">expect_popen()</a></span> でオープンした
      Expect ストリーム。
     </span>
    </dd>
   
   
    <dt><code class="parameter">cases</code></dt>
    <dd>
     <p class="para">
      expect case の配列。個々の expect case は数値添字の配列で、
      以下のような形式となります。
      <table class="doctable table">
       <caption><strong>Expect Case の配列</strong></caption>
       
        <thead>
         <tr>
          <th>添字</th>
          <th>値の型</th>
          <th>説明</th>
          <th>必須かどうか</th>
          <th>デフォルト値</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>0</td>
          <td>string</td>
          <td>ストリームからの出力との比較対象となるパターン。</td>
          <td>yes</td>
          <td class="empty">&nbsp;</td>
         </tr>

         <tr>
          <td>1</td>
          <td>mixed</td>
          <td>パターンに一致した場合にこの関数が返す値。</td>
          <td>yes</td>
          <td class="empty">&nbsp;</td>
         </tr>

         <tr>
          <td>2</td>
          <td>integer</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>、
           <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>
           あるいは
           <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">戻り値</h3>
  <p class="simpara">
   一致したパターンに関連付けられた値を返します。
  </p>
  <p class="simpara">
   この関数の実行に失敗した場合は、
   <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>
   あるいは
   <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">変更履歴</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>バージョン</th>
      <th>説明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>PECL expect 0.2.1</td>
      <td>
      バージョン 0.2.1 より前では、<code class="parameter">match</code>
      パラメータに返されるのはマッチした文字列であり、
      部分文字列の配列ではありませんでした。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 <div class="refsect1 examples" id="refsect1-function.expect-expectl-examples">
  <h3 class="title">例</h3>
  <div class="example" id="example-1">
   <p><strong>例1 <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">// ファイルをリモートホストにコピーします<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(パターン, パターンに一致した場合にこの関数が返す値)<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">// switch 文だけではなく while ループも抜けます<br />        </span><span style="color: #007700">default:<br />            die(</span><span style="color: #DD0000">"エラーが発生しました!"</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;<br /></span>?&gt;</span></code></div>
   </div>

  </div>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.expect-expectl-seealso">
  <h3 class="title">参考</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.expect-popen.php" class="function" rel="rdfs-seeAlso">expect_popen()</a> - Bourne シェル経由でコマンドを実行し、プロセスへの PTY
  ストリームをオープンする</span></li>
  </ul>
 </div>

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