Index: backend.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/backend.inc,v retrieving revision 1.15 diff -u -p -r1.15 backend.inc --- backend.inc 20 May 2009 21:26:55 -0000 1.15 +++ backend.inc 23 Sep 2009 23:49:18 -0000 @@ -56,12 +56,27 @@ */ define('DRUSH_BACKEND_OUTPUT_DELIMITER', 'DRUSH_BACKEND_OUTPUT_START>>>%s<< array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to @@ -173,7 +188,7 @@ function _drush_proc_open($cmd, $data = $info = stream_get_meta_data($pipes[1]); stream_set_blocking($pipes[1], TRUE); stream_set_timeout($pipes[1], 1); - $stream = ''; + $string = ''; while (!feof($pipes[1]) && !$info['timed_out']) { $string .= fgets($pipes[1], 4096); $info = stream_get_meta_data($pipes[1]); @@ -184,7 +199,6 @@ function _drush_proc_open($cmd, $data = $info = stream_get_meta_data($pipes[2]); stream_set_blocking($pipes[2], TRUE); stream_set_timeout($pipes[2], 1); - $stream = ''; while (!feof($pipes[2]) && !$info['timed_out']) { $string .= fgets($pipes[2], 4096); $info = stream_get_meta_data($pipes[2]); @@ -233,8 +247,13 @@ function _drush_proc_open($cmd, $data = * If the command was completed, this will return an associative array containing the data from drush_backend_output(). */ function drush_backend_invoke($command, $data = array(), $method = 'GET', $integrate = TRUE, $drush_path = NULL, $hostname = NULL, $username = NULL) { - $cmd = _drush_backend_generate_command($command, $data, $method, $drush_path, $hostname, $username); - drush_log(dt('Running: !cmd', array('!cmd' => $cmd)), 'command'); + $args = explode(" ", $command); + $command = array_shift($args); + return drush_backend_invoke_args($command, $args, $data, $method, $integrate, $drush_path, $hostname, $username); +} + +function drush_backend_invoke_args($command, $args, $data = array(), $method = 'GET', $integrate = TRUE, $drush_path = NULL, $hostname = NULL, $username = NULL) { + $cmd = _drush_backend_generate_command($command, $args, $data, $method, $drush_path, $hostname, $username); return _drush_backend_invoke($cmd, $data, $integrate); } @@ -260,6 +279,7 @@ function drush_backend_invoke($command, * If the command was completed, this will return an associative array containing the data from drush_backend_output(). */ function _drush_backend_invoke($cmd, $data = null, $integrate = TRUE) { + drush_log(dt('Running: !cmd', array('!cmd' => $cmd)), 'command'); $proc = _drush_proc_open($cmd, $data); if (($proc['code'] == DRUSH_APPLICATION_ERROR) && $integrate) { @@ -280,9 +300,11 @@ function _drush_backend_invoke($cmd, $da /** * Generate a command to execute. - + * * @param command * A defined drush command such as 'cron', 'status' or any of the available ones such as 'drush pm'. + * @param args + * An array or arguments for the command. * @param data * Optional. An array containing options to pass to the remote script. * Array items with a numeric key are treated as optional arguments to the command. @@ -308,25 +330,27 @@ function _drush_backend_invoke($cmd, $da * @return * A text string representing a fully escaped command. */ -function _drush_backend_generate_command($command, &$data, $method = 'GET', $drush_path = null, $hostname = null, $username = null) { - $drush_path = !is_null($drush_path) ? $drush_path : DRUSH_COMMAND; // Call own drush.php file. +function _drush_backend_generate_command($command, $args, &$data, $method = 'GET', $drush_path = null, $hostname = null, $username = null) { + $drush_path = !is_null($drush_path) ? $drush_path : (is_null($hostname) ? DRUSH_COMMAND : 'drush'); // Call own drush.php file on local machines, or 'drush' on remote machines. $data['root'] = ($data['root']) ? $data['root'] : drush_get_context('DRUSH_DRUPAL_ROOT'); $data['uri'] = array_key_exists('uri', $data) ? $data['uri'] : drush_get_context('DRUSH_URI'); $option_str = _drush_backend_argument_string($data, $method); - $args = explode(" ", $command); foreach ($data as $key => $arg) { if (is_numeric($key)) { $args[] = $arg; unset($data[$key]); } } - $command = ''; foreach ($args as $arg) { $command .= ' ' . escapeshellarg($arg); } + $command_shell=''; + if (".php" == substr($drush_path, strlen($drush_path) - strlen(".php"))) { + $command_shell='php '; + } // @TODO: Implement proper multi platform / multi server support. - $cmd = sprintf(escapeshellcmd("php %s %s %s --backend"), escapeshellcmd($drush_path), $option_str, $command); + $cmd = sprintf(escapeshellcmd("%s%s %s %s --backend"), escapeshellcmd($command_shell), escapeshellcmd($drush_path), $option_str, $command); if (!is_null($hostname)) { $username = (!is_null($username)) ? $username : get_current_user(); @@ -347,7 +371,9 @@ function _drush_backend_generate_command */ function drush_backend_fork($command, $data, $drush_path = null, $hostname = null, $username = null) { $data['quiet'] = TRUE; - $cmd = "(" . _drush_backend_generate_command($command, $data, 'GET', $drush_path, $hostname, $username) . ' &) > /dev/null'; + $args = explode(" ", $command); + $command = array_shift($args); + $cmd = "(" . _drush_backend_generate_command($command, $args, $data, 'GET', $drush_path, $hostname, $username) . ' &) > /dev/null'; drush_log(dt("Forking : !cmd", array('!cmd' => $cmd))); system($cmd); }