Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 5752

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Execute command via shell and return the complete output as a string</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.proc-terminate.html">proc_terminate</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.system.html">system</a></div>
 <div class="up"><a href="ref.exec.html">Program execution Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.shell-exec" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">shell_exec</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">shell_exec</span> &mdash; <span class="dc-title">Execute command via shell and return the complete output as a string</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.shell-exec-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>shell_exec</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$cmd</code></span>
   )</div>

  <p class="para rdfs-comment">
   This function is identical to the <a href="language.operators.execution.html" class="link">backtick operator</a>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.shell-exec-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">cmd</code></em></span>
     <dd>

      <p class="para">
       The command that will be executed.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.shell-exec-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   The output from the executed command or <strong><code>NULL</code></strong> if an error occurred or the
   command produces no output.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    This function can return <strong><code>NULL</code></strong> both when an error occurs or the program
    produces no output. It is not possible to detect execution failures using
    this function.  <span class="function"><a href="function.exec.html" class="function">exec()</a></span> should be used when access to the
    program exit code is required.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 examples" id="refsect1-function.shell-exec-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-3678">
    <p><strong>Example #1 A  <span class="function"><strong>shell_exec()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$output&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">shell_exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'ls&nbsp;-lart'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"&lt;pre&gt;</span><span style="color: #0000BB">$output</span><span style="color: #DD0000">&lt;/pre&gt;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.shell-exec-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    This function is disabled when PHP is running in <a href="features.safe-mode.html" class="link">safe mode</a>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.shell-exec-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.exec.html" class="function" rel="rdfs-seeAlso">exec()</a> - Execute an external program</span></li>
    <li class="member"> <span class="function"><a href="function.escapeshellcmd.html" class="function" rel="rdfs-seeAlso">escapeshellcmd()</a> - Escape shell metacharacters</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.proc-terminate.html">proc_terminate</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.system.html">system</a></div>
 <div class="up"><a href="ref.exec.html">Program execution Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>