function _drush_shell_exec

8.0.x exec.inc _drush_shell_exec($args, $interactive = FALSE)
6.x exec.inc _drush_shell_exec($args, $interactive = FALSE)
7.x exec.inc _drush_shell_exec($args, $interactive = FALSE)
4.x drush.inc _drush_shell_exec($args, $interactive = FALSE)
5.x exec.inc _drush_shell_exec($args, $interactive = FALSE)
master exec.inc _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.

Parameters

$args: The command and its arguments.

$interactive: Whether to run in

Return value

TRUE on success, FALSE on failure

See also

drush_shell_exec.

Related topics

2 calls to _drush_shell_exec()
drush_shell_exec in includes/drush.inc
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/drush.inc
Executes a command in interactive mode.

File

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

Code

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_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;
  }
}