<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.12 $ -->
<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 -->
  <refentry id="function.popen">
   <refnamediv>
    <refname>popen</refname>
    <refpurpose>Opens process file pointer</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>resource</type><methodname>popen</methodname>
      <methodparam><type>string</type><parameter>command</parameter></methodparam>
      <methodparam><type>string</type><parameter>mode</parameter></methodparam>
     </methodsynopsis>
    <para> 
     Opens a pipe to a process executed by forking the command given
     by command.
    </para>
    <para> 
     Returns a file pointer identical to that returned by
     <function>fopen</function>, except that it is unidirectional (may
     only be used for reading or writing) and must be closed with
     <function>pclose</function>. This pointer may be used with
     <function>fgets</function>, <function>fgetss</function>, and
     <function>fputs</function>.
    </para>
    <para>
     If an error occurs, returns &false;. 
    </para>
    <note>
     <para>
      If you're looking for bi-directional support (two-way), use 
      <function>proc_open</function>.
     </para>
    </note>
    <para>
     <example>
      <title><function>popen</function> example</title>
      <programlisting role="php">
<![CDATA[
<?php
$handle = popen("/bin/ls", "r");
?>
]]>
      </programlisting>
     </example>
    </para>
    <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:
     <informalexample>
      <programlisting role="php">
<![CDATA[
<?php
error_reporting(E_ALL);

/* Add redirection so we can get stderr. */
$handle = popen('/path/to/spooge 2>&1', 'r');
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
pclose($handle);
?>
]]>
      </programlisting>
     </informalexample>
    </para>
    &note.exec-path;
    &warn.sm.exec;
    <para>
     See also <function>pclose</function>, <function>fopen</function>,
     and <function>proc_open</function>.
    </para>
   </refsect1>
  </refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->