I am trying to write a Drush script locally to speed up some repetitive tasks. I am running in to issues importing a database through the script. I have tried using drush_invoke
and drush_invoke_process
to run the equivalent of drush sql-cli < C:/path/to/mysql.sql
.
I have tried several different variations with the $commandline_args
and $commandline_arguments
with no luck and Google has not been helping me much.
Does anyone have the correct syntax for this? I would also be fine with another method that works. I would prefer one that allows for a user input path to the SQL file but hard coded would work for now.
EDIT: I am using drush scr
to run the script. Just in case it makes a difference.
EDIT 2: The accepted answer from greg_1_anderson works great. To allow for using the path to the file as an argument I found that drupal_get_option works. Just add the argument --arg_name=arg_value
like drush scr script.php --file=path/to/file
. Then call the arg in the script file.
Full solution:
$file = drush_get_option('file');
$options = array(
'file' => $file,
'file-delete' => FALSE,
'strict' => FALSE,
);
drush_invoke_process($self, 'sql-query', array(), $options);
drush_invoke_process
function.