W3cubDocs

/PHP

shell_exec

(PHP 4, PHP 5, PHP 7)

shell_execExecute command via shell and return the complete output as a string

Description

shell_exec ( string $cmd ) : string

This function is identical to the 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

cmd

The command that will be executed.

Return Values

The output from the executed command or null if an error occurred 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.

Examples

Example #1 A shell_exec() example

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

See Also

© 1997–2020 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/function.shell-exec.php