STDIN, 1 => STDOUT, 2 => STDERR), $pipes); proc_close($result); // proc_open returns FALSE on failure, or a resource on success. return ($result === FALSE) ? FALSE : TRUE; } else { exec($command . ' 2>&1', $output, $result); _drush_shell_exec_output_set($output); if (drush_get_context('DRUSH_DEBUG')) { foreach ($output as $line) { drush_print($line, 2); } } // Exit code 0 means success. return ($result == 0); } } else { return TRUE; } } /** * Determine the appropriate os value for the * specified site record * * @returns * NULL for 'same as local machine', 'Windows' or 'Linux'. */ function drush_os($site_record = NULL) { // Default to $os = NULL, meaning 'same as local machine' $os = NULL; // If the site record has an 'os' element, use it if (isset($site_record) && array_key_exists('os', $site_record)) { $os = $site_record['os']; } // Otherwise, we will assume that all remote machines are Linux elseif (isset($site_record) && array_key_exists('remote-host', $site_record)) { $os = drush_get_option('remote-os', 'Linux'); } return $os; } /** * Platform-independent version of escapeshellarg(). * This only works for local commands. * TODO: Make a unified drush_escapeshellarg * that works on Linux and Windows. */ function drush_escapeshellarg($arg, $os = NULL) { if (drush_is_windows($os)) { return _drush_escapeshellarg_windows($arg); } else { return escapeshellarg($arg); } } /** * Windows version of escapeshellarg(). * * @deprecated escapeshellarg needs to be cross-platform, * because drush does not always know in advance whether an * escaped arg will be used locally or on a remote system. * See http://drupal.org/node/766080 */ function _drush_escapeshellarg_windows($arg) { // Double the backslashes before any double quotes. Escape the double quotes. // (\" => \\\") && (" => \") = // (\" => \\") + $arg = preg_replace('/\\\"/', '\\\\\\"', $arg); // + (" => \") $arg = preg_replace('/"/', '\\"', $arg); // The same with single quotes. // (\' => \\\') && (' => \') = // (\' => \\') + $arg = preg_replace('/\\\'/', '\\\\\\\'', $arg); // + (' => \') $arg = preg_replace('/\'/', '\\\'', $arg); // Replace "\t", "\n", "\r", "\0", "\x0B" with a whitespace. $arg = str_replace(array("\t", "\n", "\r", "\0", "\x0B"), ' ', $arg); // Add surrounding quotes. $arg = '"' . $arg . '"'; return $arg; } /** * Stores output for the most recent shell command. * This should only be run from drush_shell_exec(). * * @param $output * The output of the most recent shell command. * If this is not set the stored value will be returned. */ function _drush_shell_exec_output_set($output = FALSE) { static $stored_output; if ($output === FALSE) return $stored_output; $stored_output = $output; } /** * Returns the output of the most recent shell command as an array of lines. */ function drush_shell_exec_output() { return _drush_shell_exec_output_set(); } /** * @} End of "defgroup commandwrappers". */