exec
exec
Execute an external program
**exec** string $command array $output int $result_code
executes the given
.
exec``command
commandThe command that will be executed.
output
If the argument is present, then the
specified array will be filled with every line of output from the
command. Trailing whitespace, such as , is not
included in this array. Note that if the array already contains some
elements, will append to the end of the array.
If you do not want the function to append elements, call
on the array before passing it to
.
output``\n``exec``unset``exec
result_code
If the argument is present
along with the argument, then the
return status of the executed command will be written to this
variable.
result_code``output
The last line from the result of the command. If you need to execute a
command and have all the data from the command passed directly back without
any interference, use the function.
passthru
Returns false on failure.
To get the output of the executed command, be sure to set and use the
parameter.
output
Emits an if
is unable to execute the .
E_WARNING``exec``command
Throws a if
is empty or contains null bytes.
ValueError``command
Voorbeeld: An example
<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
$output=null;
$retval=null;
exec('whoami', $output, $retval);
echo "Returned with status $retval and output:\n";
print_r($output);
?>
Returned with status 0 and output:
Array
(
[0] => cmb
)
system``passthru``escapeshellcmd``pcntl_execbacktick operator