I have a module with additional (.inc) files containing functions I need to run via Drush. I know it is possible to run drush eval, but when I try to do it for those functions I get the following error:

PHP Fatal error: Call to undefined function my_module_my_function() in /usr/share/php/drush/commands/core/core.drush.inc(1037) : eval()'d code on line 1

This command works (the function is in the .module file).

drush eval 'my_module_cron();'

This command does not work (the function is in the .inc file).

drush eval 'my_module_my_function();'

Is there any workaround, besides moving the function in the module?

  • Is your inc file included/required on the module file? or in your .info file? This should work as long as drupal knows about the inc file from a .info file or it's included/required in your .module file.
    – Beebee
    Commented Jan 20, 2015 at 0:38

2 Answers 2


You could add module_load_include() to your eval code like you would anywhere else.

Like this:

drush eval "module_load_include('inc', 'my_module', 'INCLUDE_FILE_NAME_WITHOUT_EXTENSION'); my_module_my_function();"
  • Also works for .install files, for example: drush eval "module_load_include('install', 'my_module', 'my_module); my_module_install();"
    – tanius
    Commented Mar 28, 2016 at 2:05
  • This doesn't work for me. I get Division by zero core.drush.inc(1168) : eval()'d code:1 when I call module_load_include.
    – mbomb007
    Commented Nov 15, 2018 at 21:24
  • @mbomb007: what version of drush are you using and what is the command you are running?
    – rooby
    Commented Nov 16, 2018 at 3:14
  • Never mind. I was using the same type of quotes both inside and out. drush eval 'module_load_include('...
    – mbomb007
    Commented Nov 16, 2018 at 16:22

For Drupal 8 you can use the following method.

drush php-eval "module_load_include('install', 'my_module', 'my_module'); my_module_update_8020();"

I used it for running updates that were already run.

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.