mirror of
https://github.com/php/doc-es.git
synced 2026-03-24 15:32:36 +01:00
191 lines
5.5 KiB
XML
191 lines
5.5 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: b412bbd26214f7281ac7dd858710e09952a275f2 Maintainer: PhilDaiguille Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<refentry xml:id="function.exec" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>exec</refname>
|
|
<refpurpose>Ejecuta un programa externo</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>string</type><type>false</type></type><methodname>exec</methodname>
|
|
<methodparam><type>string</type><parameter>command</parameter></methodparam>
|
|
<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>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>exec</function> ejecuta el comando <parameter>command</parameter>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>command</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El comando a ejecutar.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>output</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si el argumento <parameter>output</parameter> está presente,
|
|
entonces este array será rellenado por las líneas devueltas por
|
|
el comando. Los espacios al inicio y al final de la cadena, como
|
|
<literal>\n</literal>, no serán incluidos en este array.
|
|
Cabe señalar que si este array contiene
|
|
elementos, <function>exec</function> añadirá
|
|
las nuevas líneas al final del array. Si no se desean
|
|
concatenar los nuevos elementos, utilice la función
|
|
<function>unset</function> con este array antes
|
|
de pasárselo a <function>exec</function>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>result_code</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si el argumento <parameter>result_code</parameter> está presente
|
|
además del array <parameter>output</parameter>, entonces el estado
|
|
de retorno de ejecución será escrito en esta variable.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
La última línea del resultado del comando. Para ejecutar un comando
|
|
y obtener el resultado sin ningún tratamiento, debe utilizarse la
|
|
función <function>passthru</function>.
|
|
</para>
|
|
<para>
|
|
Devuelve &false; en caso de error.
|
|
</para>
|
|
<para>
|
|
Para recuperar la salida del comando ejecutado, asegúrese de definir
|
|
y utilizar el parámetro <parameter>output</parameter>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
Emite una advertencia <constant>E_WARNING</constant> si <function>exec</function> no puede
|
|
ejecutar el comando <parameter>command</parameter>.
|
|
</para>
|
|
<para>
|
|
Levanta una excepción <classname>ValueError</classname> si <parameter>command</parameter>
|
|
está vacío o contiene bytes nulos.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.0.0</entry>
|
|
<entry>
|
|
Si <parameter>command</parameter> está vacío o contiene bytes nulos,
|
|
<function>exec</function> levanta ahora una excepción <classname>ValueError</classname>.
|
|
Anteriormente, se emitía una advertencia <constant>E_WARNING</constant> y se devolvía &false;.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo con <function>exec</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Muestra el nombre de usuario que ejecuta el proceso php/http
|
|
// (en un sistema que tenga "whoami" en el camino de ejecutables)
|
|
$output=null;
|
|
$retval=null;
|
|
exec('whoami', $output, $retval);
|
|
echo "Returned with status $retval and output:\n";
|
|
print_r($output);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
Returned with status 0 and output:
|
|
Array
|
|
(
|
|
[0] => cmb
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
&warn.escapeshell;
|
|
¬e.exec-bg;
|
|
¬e.exec-bypass-shell;
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<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">los guiones bajos</link></member>
|
|
</simplelist>
|
|
</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:"~/.phpdoc/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
|
|
-->
|