2002-04-15 00:12:54 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2003-02-10 20:19:04 +00:00
|
|
|
<!-- $Revision: 1.8 $ -->
|
2002-04-15 00:12:54 +00:00
|
|
|
<!-- 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>
|
2003-01-11 18:20:22 +00:00
|
|
|
<type>resource</type><methodname>popen</methodname>
|
2002-04-15 00:12:54 +00:00
|
|
|
<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>
|
2002-10-18 03:30:33 +00:00
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
If you're looking for bi-directional support (two-way), use
|
|
|
|
<function>proc_open</function>.
|
|
|
|
</para>
|
|
|
|
</note>
|
2002-04-15 00:12:54 +00:00
|
|
|
<para>
|
2003-02-10 20:19:04 +00:00
|
|
|
<example>
|
|
|
|
<title><function>popen</function> example</title>
|
|
|
|
<programlisting role="php">
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
2002-10-18 03:30:33 +00:00
|
|
|
<?php
|
2003-01-13 02:54:28 +00:00
|
|
|
$handle = popen ("/bin/ls", "r");
|
2002-10-18 03:30:33 +00:00
|
|
|
?>
|
2002-04-15 00:12:54 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
2003-01-27 02:50:41 +00:00
|
|
|
</example>
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<note>
|
|
|
|
<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. */
|
2003-01-13 02:54:28 +00:00
|
|
|
$handle = popen('/path/to/spooge 2>&1', 'r');
|
|
|
|
echo "'$handle'; " . gettype($handle) . "\n";
|
|
|
|
$read = fread($handle, 2096);
|
2002-04-15 00:12:54 +00:00
|
|
|
echo $read;
|
2003-01-13 02:54:28 +00:00
|
|
|
pclose($handle);
|
2002-04-15 00:12:54 +00:00
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</informalexample>
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
<para>
|
2002-10-18 03:30:33 +00:00
|
|
|
See also <function>pclose</function>, <function>fopen</function>,
|
|
|
|
and <function>proc_open</function>.
|
2002-04-15 00:12:54 +00:00
|
|
|
</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
|
|
|
|
-->
|