diff options
author | Urban Müller | 2007-04-17 14:44:46 +0000 |
---|---|---|
committer | Urban Müller | 2007-04-17 14:44:46 +0000 |
commit | 4a2ae94f1dfe091b33c4fcc1e03e64862cc943bc (patch) | |
tree | 097f0a83701dbffe8b424bf88e0fbdef4ce9832c /it.class | |
parent | 37808eebe0626ae577d7db05afcf5e6536b1ea0f (diff) | |
download | itools-4a2ae94f1dfe091b33c4fcc1e03e64862cc943bc.tar.gz itools-4a2ae94f1dfe091b33c4fcc1e03e64862cc943bc.tar.bz2 itools-4a2ae94f1dfe091b33c4fcc1e03e64862cc943bc.zip |
wrapper for shell commands
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); +} + } ?> |