diff --git a/helpers.inc.php b/helpers.inc.php index cbd434b..131dddc 100644 --- a/helpers.inc.php +++ b/helpers.inc.php @@ -373,6 +373,48 @@ function recurse_copy($src, $dst, $dir_perms = 0777, $copy_mode = COPY_MODE_BUIL closedir($dir); } +function shell($cmd, &$out=null) +{ + shell_try($cmd, $ret, $out); + if($ret != 0) + throw new TaskmanException("Shell execution error(exit code $ret)"); +} + +function shell_try($cmd, &$ret=null, &$out=null) +{ + msg(" shell: $cmd\n"); + msg(" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); + + if(func_num_args() < 3) + system($cmd, $ret); + else + _execute_proc_cmd($cmd, $ret, $out); +} + +function _execute_proc_cmd($cmd, &$ret, &$out) +{ + //TODO: do we really need to redirect error stream? + $proc = popen("$cmd 2>&1", 'r'); + + $log = ''; + //TODO: how can this be? + if(is_string($proc)) + { + $log = $proc; + _log($log, 1); + } + else + { + while($logline = fgets($proc)) + { + $log .= $logline; + _log($logline, 1); + } + } + $out = explode("\n", $log); + $ret = pclose($proc); +} + function _ensure_copy_file($src, $dst, $copy_mode = COPY_MODE_BUILTIN, $mtime_check = false) { if($mtime_check && file_exists($dst) && filemtime($src) <= filemtime($dst)) @@ -856,9 +898,9 @@ function replace_text_in_file($search_pattern, $replace_pattern, $from_file, $to function gamectl_get_props_as_php_code() { $props = props(); - $props_str = " $v) - $props_str .= "taskman_propset('$k', " . var_export($v, true). ");\n"; + $props_str .= "set('$k', " . var_export($v, true). ");\n"; return $props_str; }