summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2007-04-17 14:44:46 +0000
committerUrban Müller2007-04-17 14:44:46 +0000
commit4a2ae94f1dfe091b33c4fcc1e03e64862cc943bc (patch)
tree097f0a83701dbffe8b424bf88e0fbdef4ce9832c
parent37808eebe0626ae577d7db05afcf5e6536b1ea0f (diff)
downloaditools-4a2ae94f1dfe091b33c4fcc1e03e64862cc943bc.tar.gz
itools-4a2ae94f1dfe091b33c4fcc1e03e64862cc943bc.tar.bz2
itools-4a2ae94f1dfe091b33c4fcc1e03e64862cc943bc.zip
wrapper for shell commands
-rw-r--r--it.class28
1 files changed, 28 insertions, 0 deletions
diff --git a/it.class b/it.class
index 459691e..c3841d3 100644
--- a/it.class
+++ b/it.class
@@ -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);
+}
+
}
?>