diff --git a/includes/backend.inc b/includes/backend.inc
index 1800bea..57c6075 100644
--- a/includes/backend.inc
+++ b/includes/backend.inc
@@ -922,6 +922,8 @@ function _drush_backend_classify_options($site_record, $command_options, &$backe
  *   backend invoke results from each concurrent command.
  */
 function _drush_backend_invoke($cmds, $common_backend_options = array(), $context = NULL) {
+  $cwd = isset($common_backend_options['cwd']) ? $common_backend_options['cwd'] : NULL;
+  $env = isset($common_backend_options['env']) ? $common_backend_options['env'] : NULL;
   if (drush_get_context('DRUSH_SIMULATE') && !array_key_exists('override-simulated', $common_backend_options)) {
     foreach ($cmds as $cmd) {
       drush_print(dt('Simulating backend invoke: !cmd', array('!cmd' => $cmd['cmd'])));
@@ -938,7 +940,7 @@ function _drush_backend_invoke($cmds, $common_backend_options = array(), $contex
         $exec_cmd .= ' --quiet &';
       }
       drush_log(dt("executing !cmd", array('!cmd' => $exec_cmd)));
-      $ret = drush_shell_proc_open($exec_cmd);
+      $ret = drush_shell_proc_open($exec_cmd, $cwd, $env);
     }
     return $ret;
   }
diff --git a/includes/exec.inc b/includes/exec.inc
index 7d4a9d5..3a72766 100644
--- a/includes/exec.inc
+++ b/includes/exec.inc
@@ -224,12 +224,12 @@ function drush_shell_proc_build($site, $command = '', $cd = NULL) {
  *     1 general error
  *     127 command not found
  */
-function drush_shell_proc_open($cmd) {
+function drush_shell_proc_open($cmd, $cwd = NULL, $env = NULL) {
   if (drush_get_context('DRUSH_VERBOSE') || drush_get_context('DRUSH_SIMULATE')) {
     drush_print("Calling proc_open($cmd);", 0, STDERR);
   }
   if (!drush_get_context('DRUSH_SIMULATE')) {
-    $process = proc_open($cmd, array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes);
+    $process = proc_open($cmd, array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes, $cwd, $env);
     $proc_status = proc_get_status($process);
     $exit_code = proc_close($process);
     return ($proc_status["running"] ? $exit_code : $proc_status["exitcode"] );
diff --git a/tests/drushScriptTest.php b/tests/drushScriptTest.php
new file mode 100644
index 0000000..d68c6cf
--- /dev/null
+++ b/tests/drushScriptTest.php
@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * @file
+ *   Tests for the 'drush' script itself
+ */
+class drushScriptCase extends Drush_CommandTestCase {
+
+  /*
+   * Test drush ssh --simulate. No additional bash passed.
+   */
+  public function testPhpOptionsTest() {
+    // todo: could probably run this test on mingw
+    if ($this->is_windows()) {
+      $this->markTestSkipped('environment variable tests not currently functional on Windows.');
+    }
+
+    $options = array(
+    );
+    $env = array(
+      'PHP_OPTIONS' => '-d default_mimetype="text/drush"',
+    );
+    $this->drush('ev', array('print ini_get("default_mimetype");'), $options, NULL, NULL, self::EXIT_SUCCESS, NULL, $env);
+    $output = $this->getOutput();
+    $expected = sprintf('Calling proc_open(ssh -o PasswordAuthentication=no %s@%s);', self::escapeshellarg('user'), self::escapeshellarg('server'));
+    $this->assertEquals('text/drush', $output);
+  }
+}
diff --git a/tests/drush_testcase.inc b/tests/drush_testcase.inc
index 8a6d771..59a65e2 100644
--- a/tests/drush_testcase.inc
+++ b/tests/drush_testcase.inc
@@ -192,7 +192,7 @@ abstract class Drush_TestCase extends PHPUnit_Framework_TestCase {
    *    @access public
    */
   function getOutput() {
-    return implode("\n", $this->_output);
+    return $this->_output;
   }
 
   /**
@@ -201,7 +201,7 @@ abstract class Drush_TestCase extends PHPUnit_Framework_TestCase {
    *    @access public
    */
   function getOutputAsList() {
-    return $this->_output;
+    return explode("\n", $this->_output);
   }
 
   function webroot() {
@@ -323,10 +323,23 @@ abstract class Drush_CommandTestCase extends Drush_TestCase {
    * @return integer
    *   Exit code. Usually self::EXIT_ERROR or self::EXIT_SUCCESS.
    */
-  function execute($command, $expected_return = self::EXIT_SUCCESS) {
+  function execute($command, $expected_return = self::EXIT_SUCCESS, $cwd = NULL, $env = NULL) {
     $this->_output = FALSE;
     $this->log("Executing: $command", 'notice');
-    exec($command, $this->_output, $return);
+    $descriptorspec = array(
+      0 => array("pipe", "r"),
+      1 => array("pipe", "w") );
+    $process = proc_open($command, $descriptorspec, $pipes, $cwd, $env);
+    if (is_resource($process)) {
+      fclose($pipes[0]);
+      $this->_output = stream_get_contents($pipes[1]);
+      $this->_output = rtrim($this->_output); // one more /n than with exec
+      fclose($pipes[1]);
+      $return = proc_close($process);
+    }
+    else {
+      $return = 1;
+    }
     $this->assertEquals($expected_return, $return, 'Unexpected exit code: ' .  $command);
     return $return;
   }
@@ -351,10 +364,10 @@ abstract class Drush_CommandTestCase extends Drush_TestCase {
     * @return integer
     *   An exit code.
     */
-  function drush($command, array $args = array(), array $options = array(), $site_specification = NULL, $cd = NULL, $expected_return = self::EXIT_SUCCESS, $suffix = NULL) {
+  function drush($command, array $args = array(), array $options = array(), $site_specification = NULL, $cd = NULL, $expected_return = self::EXIT_SUCCESS, $suffix = NULL, $env = array()) {
     $global_option_list = array('simulate', 'root', 'uri', 'include', 'config', 'alias-path', 'ssh-options');
     // insert "cd ... ; drush"
-    $cmd[] = $cd ? sprintf('cd %s &&', self::escapeshellarg($cd)) : NULL;
+    // $cmd[] = $cd ? sprintf('cd %s &&', self::escapeshellarg($cd)) : NULL;
     $cmd[] = UNISH_DRUSH;
 
     // insert global options
@@ -394,7 +407,7 @@ abstract class Drush_CommandTestCase extends Drush_TestCase {
     }
     $cmd[] = $suffix;
     $exec = array_filter($cmd, 'strlen'); // Remove NULLs
-    return $this->execute(implode(' ', $exec), $expected_return);
+    return $this->execute(implode(' ', $exec), $expected_return, $cd, $env);
   }
 
   function drush_major_version() {
