tags: php exec capture title: Capturing Output of Shell Commmand To execute a system command: ```php $output = shell_exec("command args..."); // $output is string exec("command",$output); // $output is array of lines ``` To get the effect of Python`s `system.run` where we present the command as an array, we need to use ```php $args = ["echo","hello","world mr","flibble"]; $escaped_args = array_map(function($x) { return escapeshellarg($x); }, $args); $command = implode(" ",$escaped_args); $result = system($command); ``` Note that the `PATH` is a basic one with `/bin:/usr/bin:/usr/local/bin` and little else. # Resources * https://www.php.net/manual/en/function.exec.php * https://www.php.net/manual/en/function.shell-exec.php