php execute linux shell command
08 Jan 2019exec
: returns the last line of the output by default, but can provide all output as an array specifed as the second parameter.shell_exec
: returns all of the output stream as a string. 1system()
: displays output directly without using echo or print. 2passthru()
: when the output from the Unix command is binary data 3proc_open()
: proc_open — Execute a command and open file pointers for input/output 4
The error data is output from the target program’s STDERR stream. You can get access to the error data through the normal returned string from shell_exec() by appending 2>&1
to the command, which will redirect STDERR to STDOUT, the stream that you are currently seeing. 5
var_dump(shell_exec("ffmpeg -i /var/www/html/sitedomain/httpdocs/tmp/ebev1177.mp4 2>&1"));
$cwd='/tmp';
$descriptorspec = array(
// 0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w") );
$process = proc_open("php1 -v", $descriptorspec, $pipes, $cwd);
echo "stdout\n";
$stdout = stream_get_contents($pipes[1]);
var_dump($stdout);
fclose($pipes[1]);
echo "stderr\n";
$stderr = stream_get_contents($pipes[2]);
var_dump($stderr);
fclose($pipes[2]);