Class it:
/**
* Construct shell command using it::shell_command, log it, execute it and return output as string.
* @param $cmd shell command to be executed. String may contain:
* {keyword} quotes and inserts value from assoc array like ET()
* {0} .. {n} quotes and inserts positional arguments
* {-opts} array of opts => {value,true,false,null}: it::exec('ls {-opts}', ['-opts' => ["-l" => true]]);
* @param $cmd Format string with {keywords} a la ET()
* @param $args varargs, contains key => val arrays or positionals for filling in cmd line. val=null expands to nothing
* '_callback' optional closure, $fn($cmd) => print("$cmd\n") for echo, => !print($cmd) for echo and suppress
* @return output of command. shell errors not detectable, consider it::system or see /www/server/log/error_log
*/
static function exec($cmd, ...$args)
{
$args = array_reduce($args, fn($carry, $v) => array_merge($carry, (array)$v), []); # varargs to single array
$cmd = it::shell_command($cmd, $args); # NOPHPLINT
$before = gettimeofday(true);
if ((!($args['_callback'] instanceof Closure) || $args['_callback']($cmd)) && !EDC('noexec'))
$result = (string)shell_exec("set +o posix\n" . $cmd);
@it::log('exec', round((gettimeofday(true) - $before)*1000) . "\t$cmd");
return $result;
}