Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<proc_terminatesystem>
^Program execution FunctionsLast updated: Mon, 26 Oct 2026

shell_exec

(PHP 4, PHP 5, PHP 7, PHP 8)

shell_exec — Execute command via shell and return the complete output as a string

Description

function shell_exec(string $command): string|false|null

This function is identical to the deprecated backtick operator.

Note:

On Windows, the underlying pipe is opened in text mode which can cause the function to fail for binary output. Consider to use popen() instead for such cases.

Parameters

command

The command that will be executed.

Return Values

A string containing the output from the executed command, false if the pipe cannot be established or null if an error occurs or the command produces no output.

Note:

This function can return null both when an error occurs or the program produces no output. It is not possible to detect execution failures using this function. exec() should be used when access to the program exit code is required.

Errors/Exceptions

An E_WARNING level error is generated when the pipe cannot be established.

Examples

Example #1 A shell_exec() example

<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>

See Also


<proc_terminatesystem>
^Program execution FunctionsLast updated: Mon, 26 Oct 2026