1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-24 07:02:15 +01:00
Files
archived-doc-zh/reference/exec/functions/shell-exec.xml
魔王卷子 8f1715895c update exec (#344)
* Delete entities.functions.xml

* Update escapeshellarg.xml

* Update escapeshellcmd.xml

* Update exec.xml

* Update proc-close.xml

* Update proc-get-status.xml

* Update proc-get-status.xml

* Update proc-nice.xml

* Update proc-terminate.xml

* Update shell-exec.xml

* Update system.xml

* Update exec.xml

* Update proc-open.xml

* Update escapeshellarg.xml

* Update escapeshellcmd.xml

* Update exec.xml

* Update proc-get-status.xml

* Update proc-nice.xml

* Update proc-terminate.xml

* Update proc-terminate.xml

* Update shell-exec.xml

* Update system.xml
2022-09-21 15:20:00 +08:00

114 lines
3.0 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 7973fd533364af4dd6282ca9e7bee2dffec39b1c Maintainer: yuanyuqiang Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<!-- splitted from ./en/functions/exec.xml, last change in rev 1.2 -->
<refentry xml:id="function.shell-exec" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>shell_exec</refname>
<refpurpose>通过 shell 执行命令并将完整的输出以字符串的方式返回</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>string</type><type>false</type><type>null</type></type><methodname>shell_exec</methodname>
<methodparam><type>string</type><parameter>command</parameter></methodparam>
</methodsynopsis>
<para>
本函数同<link linkend="language.operators.execution">执行运算符</link>
</para>
<note>
<para>
在 Windows 上,底层管道以文本模式打开,这可能导致函数无法进行二进制输出。考虑使用
<function>popen</function> 避免这种情况。
</para>
</note>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>command</parameter></term>
<listitem>
<para>
要执行的命令。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&string; 包含已执行命令的输出,如果无法建立管道,则为
&false;,如果发生错误或者命令不产生输出则为 &null;
</para>
<note>
<para>
当进程执行过程中发生错误,或者进程不产生输出的情况下,都会返回
&null;。使用本函数无法检测执行是否成功。当需要访问程序退出代码时,应使用
<function>exec</function>
</para>
</note>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
无法建立管道时会产生 <constant>E_WARNING</constant> 级别的错误。
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>shell_exec</function> 示例</title>
<programlisting role="php">
<![CDATA[
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>exec</function></member>
<member><function>escapeshellcmd</function></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
-->