Index: includes/environment.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/environment.inc,v
retrieving revision 1.50
diff -u -p -r1.50 environment.inc
--- includes/environment.inc	30 Oct 2009 21:12:21 -0000	1.50
+++ includes/environment.inc	4 Nov 2009 18:51:42 -0000
@@ -877,6 +877,21 @@ function drush_find_php() {
     if (!empty($_ENV['_'])) {
       // '_' is an environment variable set by the shell. It contains the command that was executed.
       $php = $_ENV['_'];
+      // If the command was '/usr/bin/env php' (or '/usr/bin/env php-cli'), then $_ENV['_']
+      // will only contain the path to 'env', and will be missing the 'php' portion.
+      // Fortunately, we know what should go there:  either php-cli or php, depending
+      // on whether php-cli is available or not.  Note that we cannot use $GLOBALS['argv'][0],
+      // as this will hold the path to the drush.php file, which won't help us find php.
+      // Instead, we use the same technique as was used in the 'drush' script.
+      if ("/env" == substr($php, strlen($php) - strlen("/env"))) {
+        exec($php . ' php-cli -v >/dev/null 2>&1', $output, $result);
+        if ($result == 0) {
+          $php .= ' php-cli';
+        }
+        else {
+          $php .= ' php';
+        }
+      }
     }
     elseif (!empty($_ENV['SUDO_COMMAND'])) {
       // 'SUDO_COMMAND' is an environment variable set by the sudo program.
