summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
Diffstat (limited to 'it.class')
-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);
+}
+
}
?>