diff options
author | Nathan Gass | 2011-05-26 17:04:15 +0000 |
---|---|---|
committer | Nathan Gass | 2011-05-26 17:04:15 +0000 |
commit | c3e05a736d7ef159c212105b051516f671598865 (patch) | |
tree | 3ea81c5bf03fc2f19ce59a6e14db244b2f532b1b /it.class | |
parent | a8a336daf2755274f430c88e67d6d2c396706f4c (diff) | |
download | itools-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.class | 35 |
1 files changed, 25 insertions, 10 deletions
@@ -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!!! |