2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 06:57:16 +00:00
|
|
|
<!-- $Revision$ -->
|
2002-04-15 00:12:54 +00:00
|
|
|
<!-- splitted from ./en/functions/exec.xml, last change in rev 1.2 -->
|
2007-06-20 22:25:43 +00:00
|
|
|
<refentry xml:id="function.exec" xmlns="http://docbook.org/ns/docbook">
|
2005-04-08 20:14:52 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>exec</refname>
|
|
|
|
<refpurpose>Execute an external program</refpurpose>
|
|
|
|
</refnamediv>
|
2005-04-08 23:18:40 +00:00
|
|
|
|
|
|
|
<refsect1 role="description">
|
2005-04-08 20:14:52 +00:00
|
|
|
&reftitle.description;
|
|
|
|
<methodsynopsis>
|
2020-12-26 19:26:31 +00:00
|
|
|
<type class="union"><type>string</type><type>false</type></type><methodname>exec</methodname>
|
2005-04-08 20:14:52 +00:00
|
|
|
<methodparam><type>string</type><parameter>command</parameter></methodparam>
|
2020-12-26 19:26:31 +00:00
|
|
|
<methodparam choice="opt"><type>array</type><parameter role="reference">output</parameter><initializer>&null;</initializer></methodparam>
|
|
|
|
<methodparam choice="opt"><type>int</type><parameter role="reference">result_code</parameter><initializer>&null;</initializer></methodparam>
|
2005-04-08 20:14:52 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
|
|
|
<function>exec</function> executes the given
|
2005-04-08 23:18:40 +00:00
|
|
|
<parameter>command</parameter>.
|
2005-04-08 20:14:52 +00:00
|
|
|
</para>
|
2005-04-08 23:18:40 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
2005-04-08 20:14:52 +00:00
|
|
|
<para>
|
2005-04-08 23:18:40 +00:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>command</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The command that will be executed.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>output</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If the <parameter>output</parameter> argument is present, then the
|
|
|
|
specified array will be filled with every line of output from the
|
2005-08-04 08:54:08 +00:00
|
|
|
command. Trailing whitespace, such as <literal>\n</literal>, is not
|
2005-04-08 23:18:40 +00:00
|
|
|
included in this array. Note that if the array already contains some
|
|
|
|
elements, <function>exec</function> will append to the end of the array.
|
|
|
|
If you do not want the function to append elements, call
|
|
|
|
<function>unset</function> on the array before passing it to
|
|
|
|
<function>exec</function>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2020-12-26 19:26:31 +00:00
|
|
|
<term><parameter>result_code</parameter></term>
|
2005-04-08 23:18:40 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-12-26 19:26:31 +00:00
|
|
|
If the <parameter>result_code</parameter> argument is present
|
2005-04-08 23:18:40 +00:00
|
|
|
along with the <parameter>output</parameter> argument, then the
|
|
|
|
return status of the executed command will be written to this
|
|
|
|
variable.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2005-04-08 20:14:52 +00:00
|
|
|
</para>
|
2005-04-08 23:18:40 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
2005-04-08 20:14:52 +00:00
|
|
|
<para>
|
2005-04-08 23:18:40 +00:00
|
|
|
The last line from the result of the command. If you need to execute a
|
|
|
|
command and have all the data from the command passed directly back without
|
|
|
|
any interference, use the <function>passthru</function> function.
|
2005-04-08 20:14:52 +00:00
|
|
|
</para>
|
2020-12-26 19:26:31 +00:00
|
|
|
<para>
|
|
|
|
Returns &false; on failure.
|
|
|
|
</para>
|
2005-04-08 23:18:40 +00:00
|
|
|
<para>
|
|
|
|
To get the output of the executed command, be sure to set and use the
|
|
|
|
<parameter>output</parameter> parameter.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2005-04-08 20:14:52 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title>An <function>exec</function> example</title>
|
|
|
|
<programlisting role="php">
|
2004-02-24 02:22:26 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
// outputs the username that owns the running php/httpd process
|
|
|
|
// (on a system with the "whoami" executable in the path)
|
2020-12-09 15:46:49 +00:00
|
|
|
$output=null;
|
|
|
|
$retval=null;
|
|
|
|
exec('whoami', $output, $retval);
|
|
|
|
echo "Returned with status $retval and output:\n";
|
|
|
|
print_r($output);
|
2004-02-24 02:22:26 +00:00
|
|
|
?>
|
|
|
|
]]>
|
2005-04-08 20:14:52 +00:00
|
|
|
</programlisting>
|
2020-12-09 15:46:49 +00:00
|
|
|
&example.outputs.similar;
|
|
|
|
<screen>
|
|
|
|
<![CDATA[
|
|
|
|
Returned with status 0 and output:
|
|
|
|
Array
|
|
|
|
(
|
|
|
|
[0] => cmb
|
|
|
|
)
|
|
|
|
]]>
|
|
|
|
</screen>
|
2005-04-08 20:14:52 +00:00
|
|
|
</example>
|
|
|
|
</para>
|
2005-04-08 23:18:40 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="notes">
|
|
|
|
&reftitle.notes;
|
2005-04-08 20:14:52 +00:00
|
|
|
&warn.escapeshell;
|
|
|
|
¬e.exec-bg;
|
2017-04-04 09:00:34 +00:00
|
|
|
¬e.exec-bypass-shell;
|
2005-04-08 23:18:40 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
2005-04-08 20:14:52 +00:00
|
|
|
<para>
|
2005-04-08 23:18:40 +00:00
|
|
|
<simplelist>
|
|
|
|
<member><function>system</function></member>
|
|
|
|
<member><function>passthru</function></member>
|
|
|
|
<member><function>escapeshellcmd</function></member>
|
|
|
|
<member><function>pcntl_exec</function></member>
|
|
|
|
<member><link linkend="language.operators.execution">backtick operator</link></member>
|
|
|
|
</simplelist>
|
2005-04-08 20:14:52 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2002-04-15 00:12:54 +00:00
|
|
|
<!-- 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
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2002-04-15 00:12:54 +00:00
|
|
|
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
|
|
|
|
-->
|