php-doc-en/functions/exec.sgml
James Gingerich 82c6591284 Many minor cleanups.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@9864 c90b9560-bf6c-de11-be94-00142212c4b1
1999-06-20 03:04:56 +00:00

150 lines
6.3 KiB
Text

<reference id="ref.exec">
<title>Program Execution functions</title>
<titleabbrev>Program Execution</titleabbrev>
<refentry id="function.escapeshellcmd">
<refnamediv>
<refname>escapeshellcmd</refname>
<refpurpose>escape shell metacharacters</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>escapeshellcmd</function></funcdef>
<paramdef>string <parameter>command</parameter></paramdef>
</funcsynopsis>
<para>
<function>EscapeShellCmd</function> escapes any characters in a string that
might be used to trick a shell command into executing arbitrary commands.
This function should be used to make sure that any data coming from user
input is escaped before this data is passed to the <function>exec</function> or <function>system</function>
functions. A standard use would be:
<para>
<informalexample>
<programlisting>
system(EscapeShellCmd($cmd))
</programlisting>
</informalexample>
</refsect1>
</refentry>
<refentry id="function.exec">
<refnamediv>
<refname>exec</refname>
<refpurpose>Execute an external program</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>exec</function></funcdef>
<paramdef>string <parameter>command</parameter></paramdef>
<paramdef>string <parameter><optional>array</optional></parameter></paramdef>
<paramdef>int <parameter><optional>return_var</optional></parameter></paramdef>
</funcsynopsis>
<para>
<function>exec</function> executes the given <parameter>command</parameter>, however it does not
output anything. It simply returns 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.
<para>
If the <parameter>array</parameter> argument is present, then the specified array will be filled
with every line of output from the command. 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>
If the <parameter>return_var</parameter> argument is present along with the <parameter>array</parameter>
argument, then the return status of the executed command will be written to this
variable.
<para>
Note that if you are going to allow data coming from user input to be
passed to this function, then you should be using <function>EscapeShellCmd</function>
to make sure that users cannot trick the system into executing arbitrary commands.
<para>
See also <function>system</function>, <function>PassThru</function>,
<function>popen</function> and <function>EscapeShellCmd</function>.
</refsect1>
</refentry>
<refentry id="function.system">
<refnamediv>
<refname>system</refname>
<refpurpose>Execute an external program and display output</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>system</function></funcdef>
<paramdef>string <parameter>command</parameter></paramdef>
<paramdef>int <parameter><optional>return_var</optional></parameter></paramdef>
</funcsynopsis>
<para>
<function>System</function> is just like the C version of the function in that it executes
the given <parameter>command</parameter> and outputs the result. If a variable is provided as
the second argument, then the return status code of the executed command
will be written to this variable.
<para>
Note, that if you are going to allow data coming from user input to be passed to this function,
then you should be using the <function>EscapeShellCmd</function> function
to make sure that users cannot trick the system into executing arbitrary commands.
<para>
The <function>System</function> call also tries to automatically flush the web server's output
buffer after each line of output if PHP is running as a server module.
<para>
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. See also the <function>exec</function> and <function>popen</function> functions.
</refsect1>
</refentry>
<refentry id="function.passthru">
<refnamediv>
<refname>passthru</refname>
<refpurpose>Execute an external program and display raw output</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>passthru</function></funcdef>
<paramdef>string <parameter>command</parameter></paramdef>
<paramdef>int <parameter><optional>return_var</optional></parameter></paramdef>
</funcsynopsis>
<para>
The <function>passthru</function> function is similar to the
<function>Exec</function> function in that it executes a
<parameter>command</parameter>. If the
<parameter>return_var</parameter> argument is present, the return
status of the Unix command will be placed here. This function
should be used in place of <function>Exec</function> or
<function>System</function> when the output from the Unix command
is binary data which needs to be passed directly back to the
browser. A common use for this is to execute something like the
pbmplus utilities that can output an image stream directly. By
setting the content-type to <emphasis>image/gif</emphasis> and
then calling a pbmplus program to output a gif, you can create
PHP scripts that output images directly.
<para>
See also <function>exec</function> and <function>fpassthru</function>.
</refsect1>
</refentry>
</reference>
<!-- 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
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->