I am trying to download module using Drush API via drush script as following:

#!/usr/bin/env drush

// check if we can bootstrap
$self = drush_sitealias_get_record('@self');
if (empty($self)) {
    drush_die("I can't bootstrap from the current location.", 0);

// goes to site directory
drush_op('chdir', $self['root']);

drush_include_engine('drupal', 'environment', drush_drupal_major_version());

//****how to download module



While i see an Drush API for enabling, i don't see for downloading a module
How to download a module via Drush API from the script? Is there Drush API for automatically detect dependencies, download them and enable? Thank You

Drupal 7, Drush 5.8, Mac

1 Answer 1


If there's an API for this, I think it would be drush_invoke_process. I believe Drush uses that function internally when one command wants to execute another.

The primary function that executes the download work is drush_pm_download(), so you could probably just call it directly as well.

And of course, as a last resort, you could use exec(drush @alias dl $module).

  • 3
    Yes, drush_invoke_process("@self", "pm-download", array("uuid")); is definitely the way to go here. As for Drupal functions such as module_enable, you don't need to call the Drush function -- you may call the Drupal function directly. That is much better than using drush_include_engine, which I would encourage you to stay away from. Use drush_invoke_process("@self", "pm-enable", array("uuid")) if you must use Drush to enable the module. Jan 5, 2014 at 2:08
  • Thank you that worked. Greg, thanks for the tip on running Drupal functions directly...i wasn't aware those are available when run as drush script
    – latvian
    Jan 5, 2014 at 5:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.