To execute a system command:
$output = shell_exec("command args..."); // $output is string
exec("command",$output); // $output is array of lines
To get the effect of Pythonssystem.run` where we present the command as an array,
we need to use
$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