function _drush_shell_exec

8.0.x _drush_shell_exec($args, $interactive = FALSE)
6.x _drush_shell_exec($args, $interactive = FALSE)
7.x _drush_shell_exec($args, $interactive = FALSE)
4.x _drush_shell_exec($args, $interactive = FALSE)
5.x _drush_shell_exec($args, $interactive = FALSE)
master _drush_shell_exec($args, $interactive = FALSE)

Internal function: executes a shell command on the local machine. This function should not be used in instances where ssh is utilized to execute a command remotely; otherwise, remote operations would fail if executed from a Windows machine to a remote Linux server.


$args: The command and its arguments.

$interactive: Whether to run in

Return value

TRUE on success, FALSE on failure

See also


Related topics

2 calls to _drush_shell_exec()
drush_shell_exec in includes/
Executes a shell command. Output is only printed if in verbose mode. Output is stored and can be retrieved using drush_shell_exec_output(). If in simulation mode, no action is taken.
drush_shell_exec_interactive in includes/
Executes a command in interactive mode.


includes/, line 1317
The drush API implementation and helpers.


function _drush_shell_exec($args, $interactive = FALSE) {
  //do not change the command itself, just the parameters.
  for ($x = 1; $x < sizeof($args); $x++) {
    $args[$x] = drush_escapeshellarg($args[$x]);
  $command = call_user_func_array('sprintf', $args);

  if (drush_get_context('DRUSH_VERBOSE') || drush_get_context('DRUSH_SIMULATE')) {
    drush_print('Executing: ' . $command);

  if (!drush_get_context('DRUSH_SIMULATE')) {
    if ($interactive) {
      $result = proc_open($command, array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes);
      // proc_open returns FALSE on failure, or a resource on success.
      return ($result === FALSE) ? FALSE : TRUE;
    else {
      exec($command . ' 2>&1', $output, $result);

      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;