From 646480cd9ae7e60fff4b18bfb7d6863388703555 Mon Sep 17 00:00:00 2001
From: James Sinclair <jrsinclair@gmail.com>
Date: Wed, 9 Mar 2011 16:46:11 +1100
Subject: [PATCH] Changes to make udpb work in windows

---
 includes/backend.inc |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/includes/backend.inc b/includes/backend.inc
index b08896e..bce9f00 100644
--- a/includes/backend.inc
+++ b/includes/backend.inc
@@ -225,6 +225,7 @@ function _drush_backend_integrate($data) {
  *   called, the output of the command, and the error code of the command.
  */
 function _drush_proc_open($cmd, $data = NULL, $context = NULL) {
+  echo "Proc opening $cmd\n";
   $descriptorspec = array(
      0 => 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
@@ -406,6 +407,7 @@ function drush_backend_invoke_sitealias($site_record, $command, $args, $data = a
  *   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) {
+  echo "cmd is: $cmd\n";
   if (drush_get_context('DRUSH_SIMULATE') && !array_key_exists('#override-simulated', $data)) {
     drush_print(dt('Simulating backend invoke: !cmd', array('!cmd' => $cmd)));
     return FALSE;
@@ -552,7 +554,24 @@ function _drush_backend_generate_command_sitealias($site_record, $command, $args
   }
   $interactive = ' ' . (empty($data['#interactive']) ? '' : ' > `tty`') . ' 2>&1';
   // @TODO: Implement proper multi platform / multi server support.
-  $cmd = escapeshellcmd($drush_path) . " " . $option_str . " " . $command . (empty($data['#interactive']) ? " --backend" : "");
+  
+  $escaped_drush_path = '';
+  if ($os === 'Windows') {
+    $drush_path_arr  = preg_split('/\s+--/', $drush_path);
+    $drush_base_path = array_shift($drush_path_arr);
+    $drush_base_path = '"' . preg_replace('/.php$/', '.bat', $drush_base_path) . '"';
+    $drush_base_path = 'drush.bat ';
+    $escaped_drush_path = $drush_base_path . implode(' --', $drush_path_arr);
+  }
+  else {
+      $escaped_drush_path = escapeshellcmd($drush_path);
+  }
+  
+  $cmd = $escaped_drush_path . " " . $option_str . " " . $command . (empty($data['#interactive']) ? " --backend" : "");
+  
+  if ($os === 'Windows') {
+    $cmd = preg_replace('/\s*--backend$/', '', $cmd);
+  }
 
   if (!is_null($hostname)) {
     $username = (!is_null($username)) ? $username : get_current_user();
-- 
1.7.4.msysgit.0

