summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
authorNathan Gass2011-05-26 17:04:15 +0000
committerNathan Gass2011-05-26 17:04:15 +0000
commitc3e05a736d7ef159c212105b051516f671598865 (patch)
tree3ea81c5bf03fc2f19ce59a6e14db244b2f532b1b /it.class
parenta8a336daf2755274f430c88e67d6d2c396706f4c (diff)
downloaditools-c3e05a736d7ef159c212105b051516f671598865.tar.gz
itools-c3e05a736d7ef159c212105b051516f671598865.tar.bz2
itools-c3e05a736d7ef159c212105b051516f671598865.zip
factor out it::shell_command from it::exec
Diffstat (limited to 'it.class')
-rw-r--r--it.class35
1 files changed, 25 insertions, 10 deletions
diff --git a/it.class b/it.class
index 8178221..6ec2ca2 100644
--- a/it.class
+++ b/it.class
@@ -444,7 +444,7 @@ static function filter_keys($array, $keys, $p = array())
/**
- * Construct shell command, log it, execute it and return output as string.
+ * Construct shell command using it::shell_command, log it, execute it and return output as string.
* Keywords {keyword} are replace a la ET(), {-opts} takes an array and
* inserts options a la it_html attributes (value, true, false or null)
* @param $cmd Format string with {keywords} replace a la ET()
@@ -454,6 +454,29 @@ static function filter_keys($array, $keys, $p = array())
static function exec(/* $cmd, $values1 = array(), ... */)
{
$args = func_get_args();
+ $cmd = call_user_func_array('it::shell_command', $args);
+
+ $s = gettimeofday();
+ $result = EDC('noexec') ? "" : (string)shell_exec($cmd);
+ $e = gettimeofday();
+ $msec= intval(($e['sec'] - $s['sec']) * 1000 + ($e['usec'] - $s['usec']) / 1000);
+
+ @it::log('exec', "$msec\t$cmd");
+
+ return $result;
+}
+
+/**
+ * Construct shell command
+ * Keywords {keyword} are replace a la ET(), {-opts} takes an array and
+ * inserts options a la it_html attributes (value, true, false or null)
+ * @param $cmd Format string with {keywords} replace a la ET()
+ * @param $values (zero, one or more arrays can be passed)
+ * @return output of command. shell errors not detectable, see error_log in /www/server/logs
+ */
+static function shell_command(/* $cmd, $values1 = array(), ... */)
+{
+ $args = func_get_args();
$cmd = array_shift($args);
$values = array();
@@ -490,15 +513,7 @@ static function exec(/* $cmd, $values1 = array(), ... */)
$cmd = strtr($cmd, (array)$replacements); # Use strtr behaviour of going through source string once
setlocale(LC_CTYPE, $oldlocale);
-
- $s = gettimeofday();
- $result = EDC('noexec') ? "" : (string)shell_exec($cmd);
- $e = gettimeofday();
- $msec= intval(($e['sec'] - $s['sec']) * 1000 + ($e['usec'] - $s['usec']) / 1000);
-
- @it::log('exec', "$msec\t$cmd");
-
- return $result;
+ return $cmd;
}
#fails with C locale!!!