3

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?

6
  • What command do you want to run and why? Commented Jan 9, 2015 at 11:24
  • It's a command that activates/deactivates a table when the stocks are 0. Commented Jan 9, 2015 at 11:27
  • it also schedules a clear cache after 3 minutes or so. Commented Jan 9, 2015 at 11:29
  • You may use a cron instead Commented Jan 9, 2015 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? Commented Jan 9, 2015 at 12:10

2 Answers 2

4

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

$values = drush_invoke_process("@site", "cc", array("all"), array("verbose")); 
1
  • 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? Commented Jul 17, 2018 at 10:44
0

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.