diff options
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -273,5 +273,33 @@ function filter_keys($array, $keys) return $result; } + +/** + * Construct shell command, log it, execute it and return output as string. + * @param varargs: scalars for cmd and arguments, assoc arrays to specify opts and opt values + * @return output of command. shell errors not detectable, see error_log in /www/server/logs + */ +function exec(/* ... */) +{ + $args = func_get_args(); + $parts = array(); + + foreach ($args as $arg) + { + foreach ((array)$arg as $key => $val) + { + if (it::match('^-', $val)) + it::fatal("leading - in value"); + else + $parts[] = (is_int($key) ? "" : escapeshellarg($key) . " ") . escapeshellarg($val); + } + } + + $cmd = join(" ", $parts); + it::log('exec', $cmd); + + return (string)shell_exec($cmd); +} + } ?> |