<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/features.commandline.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'features.commandline.io-streams.php',
    1 => 'Flux I/O',
    2 => 'Flux d\'entr&eacute;e/sortie',
  ),
  'up' => 
  array (
    0 => 'features.commandline.php',
    1 => 'Utilisation des lignes de commande',
  ),
  'prev' => 
  array (
    0 => 'features.commandline.usage.php',
    1 => 'Utilisation',
  ),
  'next' => 
  array (
    0 => 'features.commandline.interactive.php',
    1 => 'Shell Interactif',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'features/commandline.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="features.commandline.io-streams" class="section">
  <h2 class="title">Flux d&#039;entrée/sortie</h2>
  
  
  <p class="para">
   Le <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr> définit quelques constantes pour les flux I/O pour
   rendre la programmation en ligne de commande plus facile.
  </p>
  
  <p class="para">
   <table class="doctable table">
    <caption><strong>Constantes spécifiques CLI</strong></caption>
    
     <thead>
      <tr>
       <th>Constante</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td><strong><code><a href="reserved.constants.php#constant.stdin">STDIN</a></code></strong></td>
       <td>
        <p class="para">
         Un flux déjà ouvert vers <code class="literal">stdin</code>. Ceci évite de
         l&#039;ouvrir explicitement avec
         <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$stdin </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://stdin'</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
         </div>

         Pour lire une seule ligne depuis <code class="literal">stdin</code>,
         il est possible d&#039;utiliser
         <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$line </span><span style="color: #007700">= </span><span style="color: #0000BB">trim</span><span style="color: #007700">(</span><span style="color: #0000BB">fgets</span><span style="color: #007700">(</span><span style="color: #0000BB">STDIN</span><span style="color: #007700">)); </span><span style="color: #FF8000">// lit une ligne depuis STDIN<br /></span><span style="color: #0000BB">fscanf</span><span style="color: #007700">(</span><span style="color: #0000BB">STDIN</span><span style="color: #007700">, </span><span style="color: #DD0000">"%d\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">$number</span><span style="color: #007700">); </span><span style="color: #FF8000">// lit des nombres depuis STDIN<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
         </div>

        </p>
       </td>
      </tr>

      <tr>
       <td><strong><code><a href="reserved.constants.php#constant.stdout">STDOUT</a></code></strong></td>
       <td>
        <p class="para">
         Un flux déjà ouvert vers <code class="literal">stdout</code>. Ceci évite de
         l&#039;ouvrir explicitement avec
         <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$stdout </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://stdout'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
         </div>

        </p>
       </td>
      </tr>

      <tr>
       <td><strong><code><a href="reserved.constants.php#constant.stderr">STDERR</a></code></strong></td>
       <td>
        <p class="para">
         Un flux déjà ouvert vers <code class="literal">stderr</code>.
         Ceci évite de l&#039;ouvrir explicitement avec
         <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$stderr </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://stderr'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
         </div>

        </p>
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
  
  <p class="para">
   Ainsi, il n&#039;est pas nécessaire d&#039;ouvrir un flux spécifique pour, par exemple,
   <code class="literal">stderr</code> mais il suffit d&#039;utiliser la constante
   correspondante à ce flux :
   <div class="example-contents">
<div class="shellcode"><pre class="shellcode">php -r &#039;fwrite(STDERR, &quot;stderr\n&quot;);&#039;</pre>
</div>
   </div>

   Il n&#039;est pas nécessaire de clore explicitement ces flux, sachant qu&#039;ils le seront
   automatiquement par PHP à la fin du script.
  </p>
  
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Ces constantes ne sont pas disponibles lors d&#039;une lecture d&#039;un
    script PHP depuis <code class="literal">stdin</code>.
   </p>
  </p></blockquote>
 </div><?php manual_footer($setup); ?>