Is there a way to run a Drush command using a module? I tried exec("drush ..."); but I have found out it is not recommended. Is there any other command I could use?

  • What command do you want to run and why?
    – sanzante
    Jan 9 '15 at 11:24
  • It's a command that activates/deactivates a table when the stocks are 0. Jan 9 '15 at 11:27
  • it also schedules a clear cache after 3 minutes or so. Jan 9 '15 at 11:29
  • You may use a cron instead
    – sanzante
    Jan 9 '15 at 12:04
  • Any tips how I can use cron? I'm not that used to it yet. How can I assign it to a cron job? Jan 9 '15 at 12:10

It is better to use drush_invoke_process() rather than exec().

$values = drush_invoke_process("@site", "cc", array("all"), array("verbose"));
  • 3
    drush_sitealias_get_record and drush_invoke_process are undefined. Do i need to include any class or file in my custom drupal 8 module? Jul 17 '18 at 10:44

drush_invoke_process() can be used in a drush context. Since cron is executed via drush you can used it inside a cron.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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