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– sanzante2015-01-09 11:24:38 +00:00Commented Jan 9, 2015 at 11:24
- It's a command that activates/deactivates a table when the stocks are 0.Kronk by the minute– Kronk by the minute2015-01-09 11:27:59 +00:00Commented Jan 9, 2015 at 11:27
- it also schedules a clear cache after 3 minutes or so.Kronk by the minute– Kronk by the minute2015-01-09 11:29:43 +00:00Commented Jan 9, 2015 at 11:29
- You may use a cron insteadsanzante– sanzante2015-01-09 12:04:08 +00:00Commented 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?Kronk by the minute– Kronk by the minute2015-01-09 12:10:03 +00:00Commented Jan 9, 2015 at 12:10
| Show 1 more comment
2 Answers
It is better to use drush_invoke_process() rather than exec().
$values = drush_invoke_process("@site", "cc", array("all"), array("verbose")); - 3drush_sitealias_get_record and drush_invoke_process are undefined. Do i need to include any class or file in my custom drupal 8 module?Tejas Vaidya– Tejas Vaidya2018-07-17 10:44:24 +00:00Commented Jul 17, 2018 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.