<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.filesystem.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.popen.php',
    1 => 'popen',
    2 => 'Opens process file pointer',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Функції Файлової Системи',
  ),
  'prev' => 
  array (
    0 => 'function.pclose.php',
    1 => 'pclose',
  ),
  'next' => 
  array (
    0 => 'function.readfile.php',
    1 => 'readfile',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/filesystem/functions/popen.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.popen" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">popen</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">popen</span> &mdash; <span class="dc-title">Opens process file pointer</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.popen-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>popen</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$command</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$mode</code></span>): <span class="type"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Opens a pipe to a process executed by forking the command given
   by <code class="parameter">command</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.popen-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">command</code></dt>
     <dd>
      <p class="para">
       The command
      </p>
     </dd>
    
    
     <dt><code class="parameter">mode</code></dt>
     <dd>
      <p class="para">
       The mode. Either <code class="literal">&#039;r&#039;</code> for reading, or <code class="literal">&#039;w&#039;</code>
       for writing.
      </p>
      <p class="para">
       On Windows, <span class="function"><strong>popen()</strong></span> defaults to text mode, i.e. any <code class="literal">\n</code>
       characters written to or read from the pipe will be translated to <code class="literal">\r\n</code>.
       If this is not desired, binary mode can be enforced by setting <code class="parameter">mode</code>
       to <code class="literal">&#039;rb&#039;</code> and <code class="literal">&#039;wb&#039;</code>, respectively.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.popen-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns a file pointer identical to that returned by
   <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span>, except that it is unidirectional (may
   only be used for reading or writing) and must be closed with
   <span class="function"><a href="function.pclose.php" class="function">pclose()</a></span>. This pointer may be used with
   <span class="function"><a href="function.fgets.php" class="function">fgets()</a></span>, <span class="function"><a href="function.fgetss.php" class="function">fgetss()</a></span>, and
   <span class="function"><a href="function.fwrite.php" class="function">fwrite()</a></span>. When the mode is &#039;r&#039;, the returned
   file pointer equals to the STDOUT of the command, when the mode
   is &#039;w&#039;, the returned file pointer equals to the STDIN of the
   command.
  </p>
  <p class="para">
   If an error occurs, returns <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.popen-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>popen()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$handle </span><span style="color: #007700">= </span><span style="color: #0000BB">popen</span><span style="color: #007700">(</span><span style="color: #DD0000">"/bin/ls"</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>

   </div>
  </p>
  <p class="para">
   If the command to be executed could not be found, a valid
   resource is returned. This may seem odd, but makes sense; it
   allows you to access any error message returned by the shell:
   <div class="example" id="example-2">
    <p><strong>Приклад #2 <span class="function"><strong>popen()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />error_reporting</span><span style="color: #007700">(</span><span style="color: #0000BB">E_ALL</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Add redirection so we can get stderr. */<br /></span><span style="color: #0000BB">$handle </span><span style="color: #007700">= </span><span style="color: #0000BB">popen</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/to/executable 2&gt;&amp;1'</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"'</span><span style="color: #0000BB">$handle</span><span style="color: #DD0000">'; " </span><span style="color: #007700">. </span><span style="color: #0000BB">gettype</span><span style="color: #007700">(</span><span style="color: #0000BB">$handle</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$read </span><span style="color: #007700">= </span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$handle</span><span style="color: #007700">, </span><span style="color: #0000BB">2096</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$read</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">pclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$handle</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 notes" id="refsect1-function.popen-notes">
  <h3 class="title">Примітки</h3>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    If you&#039;re looking for bi-directional support (two-way), use
    <span class="function"><a href="function.proc-open.php" class="function">proc_open()</a></span>.
   </p>
  </p></blockquote>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.popen-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.pclose.php" class="function" rel="rdfs-seeAlso">pclose()</a> - Closes process file pointer</span></li>
    <li><span class="function"><a href="function.fopen.php" class="function" rel="rdfs-seeAlso">fopen()</a> - Opens file or URL</span></li>
    <li><span class="function"><a href="function.proc-open.php" class="function" rel="rdfs-seeAlso">proc_open()</a> - Execute a command and open file pointers for input/output</span></li>
   </ul>
  </p>
 </div>


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