/** * Executes an SVN command. * @param string $cmd Command to execute * @param string $switch Switches to be applied for the given command * @param string $arg Arguments of the command * @return array Result array containing commandline (idx = IDX_CMDLINE), * standard out array (idx = IDX_STDOUT), error array (idx = IDX_ERROUT), * and return code of the command (idx = IDX_CMD_RC). * * @since v1.0.0 */ function &ExecSvnCmd($cmd, $arg = '', $switches = '') { $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); set_time_limit(100); $cwd = NULL; //'/tmp'; $pipes = NULL; if (is_array($arg)) { $arg = implode(" ", array_map("escapeshellarg", $arg)); } else { $arg = escapeshellarg(SystemTextEncoding::toUTF8($arg)); } $cmdline = (SVNLIB_PATH != "" ? SVNLIB_PATH . "/" : "") . $cmd . " " . $switches . " " . $arg; /* $output = shell_exec($cmdline); $result = array(); $result[IDX_CMDLINE] = $cmdline; if (strpos($switches, "xml")) { $result[IDX_STDOUT] = $output; } else { $result[IDX_STDOUT] = explode("\n", $output); } $result[IDX_ERROUT] = ""; return $result; */ $env = null; if (defined('AJXP_LOCALE')) { $env = array("LC_ALL" => AJXP_LOCALE); } $process = proc_open($cmdline, $descriptorspec, $pipes, NULL, $env, array("bypass_shell" => false)); $result = array(); $result[IDX_CMDLINE] = $cmdline; $result[IDX_STDOUT] = array(); $result[IDX_ERROUT] = array(); $result[IDX_CMD_RC] = -1; if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // 2 => readable handle connected to child errout fclose($pipes[0]); $result = array(); $result[IDX_CMDLINE] = $cmdline; if (strpos($switches, "xml")) { $result[IDX_STDOUT] = GetLineString($pipes[1]); } else { $result[IDX_STDOUT] = GetLineArray($pipes[1]); } fclose($pipes[1]); $result[IDX_ERROUT] = GetLineArray($pipes[2]); fclose($pipes[2]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $result[IDX_CMD_RC] = proc_close($process); // echo "CMD: $cmdline<br/>"; // PrintDebugArray($result, "Result"); } if (is_array($result[IDX_ERROUT]) && count($result[IDX_ERROUT])) { $join = trim(implode("", $result[IDX_ERROUT])); if ($join != "") { throw new Exception($join); } } return $result; }
/** * Executes an SVN command. * @param string $cmd Command to execute * @param string $switch Switches to be applied for the given command * @param string $arg Arguments of the command * @return array Result array containing commandline (idx = IDX_CMDLINE), * standard out array (idx = IDX_STDOUT), error array (idx = IDX_ERROUT), * and return code of the command (idx = IDX_CMD_RC). * * @since v1.0.0 */ function &ExecSvnCmd($cmd, $arg = '', $switches = '') { $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); set_time_limit(100); $cwd = NULL; //'/tmp'; $pipes = NULL; $cmdline = $cmd . " " . $switches . " " . $arg; /* $output = shell_exec($cmdline); $result = array(); $result[IDX_CMDLINE] = $cmdline; if(strpos($switches, "xml")){ $result[IDX_STDOUT] = $output; }else{ $result[IDX_STDOUT] = explode("\n", $output); } $result[IDX_ERROUT] = ""; return $result; */ $process = proc_open($cmdline, $descriptorspec, $pipes, NULL, NULL, array("bypass_shell" => false)); $result = array(); $result[IDX_CMDLINE] = $cmdline; $result[IDX_STDOUT] = array(); $result[IDX_ERROUT] = array(); $result[IDX_CMD_RC] = -1; if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // 2 => readable handle connected to child errout fclose($pipes[0]); $result = array(); $result[IDX_CMDLINE] = $cmdline; if (strpos($switches, "xml")) { $result[IDX_STDOUT] = GetLineString($pipes[1]); } else { $result[IDX_STDOUT] = GetLineArray($pipes[1]); } fclose($pipes[1]); $result[IDX_ERROUT] = GetLineArray($pipes[2]); fclose($pipes[2]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $result[IDX_CMD_RC] = proc_close($process); // echo "CMD: $cmdline<br/>"; // PrintDebugArray($result, "Result"); } return $result; }