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/exec.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/exec.inc
Executes a command in interactive mode.

File

includes/exec.inc, line 126
Functions for executing system commands. (e.g. exec(), system(), ...).

Code

function _drush_shell_exec($args, $interactive = FALSE) {
  // Do not change the command itself, just the parameters.
  for ($x = 1; $x < count($args); $x++) {
    $args[$x] = drush_escapeshellarg($args[$x]);
  }
  // Important: we allow $args to take one of two forms here.  If
  // there is only one item in the array, it is the already-escaped
  // command string, but otherwise sprintf is used.  In the case
  // of pre-escaped strings, sprintf will fail if any of the escaped
  // parameters contain '%', so we must not call sprintf unless necessary.
  if (count($args) == 1) {
    $command = $args[0];
  }
  else {
    $command = call_user_func_array('sprintf', $args);
  }

  if (drush_get_context('DRUSH_VERBOSE') || drush_get_context('DRUSH_SIMULATE')) {
    drush_print('Executing: ' . $command, 0, STDERR);
  }
  if (!drush_get_context('DRUSH_SIMULATE')) {
    if ($interactive) {
      $result = drush_shell_proc_open($command);
      return ($result == 0) ? TRUE : FALSE;
    }
    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;
  }
}