11

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 Jan 20 '15 at 0:38
17

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 Mar 28 '16 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 Nov 15 '18 at 21:24
  • @mbomb007: what version of drush are you using and what is the command you are running? – rooby Nov 16 '18 at 3:14
  • Never mind. I was using the same type of quotes both inside and out. drush eval 'module_load_include('... – mbomb007 Nov 16 '18 at 16:22

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.