function drush_shell_exec

8.0.x drush_shell_exec($cmd)
6.x drush_shell_exec($cmd)
7.x drush_shell_exec($cmd)
3.x drush_shell_exec($cmd)
4.x drush_shell_exec($cmd)
5.x drush_shell_exec($cmd)
master drush_shell_exec($cmd)

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.


$cmd: The command to execute. May include placeholders used for sprintf.

...: Values for the placeholders specified in $cmd. Each of these will be passed through escapeshellarg() to ensure they are safe to use on the command line.

Return value

0 if success.

13 calls to drush_shell_exec()
drush_core_call_rsync in commands/core/
Make a direct call to rsync after the source and destination paths have been evaluated.
drush_pm_cvs in commands/pm/package_handler/
General CVS helper function
drush_pm_download in commands/pm/
Command callback. Download Drupal core or any project.
drush_pm_include_version_control in commands/pm/
A simple factory function that tests for version control systems, in a user specified order, and return the one that appears to be appropriate for a specific directory.
drush_pm_version_control_bzr::bzr_get_repository_root in commands/pm/version_control/
Helper function: get the root of a repository path.

... See full list


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


function drush_shell_exec($cmd) {
  $args = func_get_args();

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

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

  if (!drush_get_context('DRUSH_SIMULATE')) {
    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 0;