I'm getting into my first drush command and coming up with a ton of things I don't understand. Basically, I need to output a list of image files referenced in my content, and the best seemed to be to output it in a table format so that the different bits of information would be easy to see and distinguish from each other.

I started by following the tutorial and did this (in the COMMAND_drush_command $items array):

    'engines' => array(
        'outputformat' => array(
            'default' => 'table',
            'pipe-format' => 'json',
            // Commands that return deep arrays will usually use
            // machine-ids for the column data.  A 'field-labels'
            // item maps from the machine-id to a human-readable label.
            'field-labels' => array(
                'node' => 'Nid',
                'title' => 'Title',
                'filename' => 'Filename',
                'directory' => 'Directory',
            // In table format, the 'column-widths' item is consulted
            // to determine the default weights for any named column.
            'column-widths' => array(
                'title' => 20,
            'require-engine-capability' => array('format-table'),

That worked fine, because I built an array of output line by line and at the end of the command passed it back to drush which duly printed it. The only problem is that there is a LOT of data, so the command gives the appearance of hanging. So I thought I would try to print line by line and did this instead:

            $result[0] = array(
                'node' => $nid,
                'title' => $title,
                'filename' => end($file),
                'directory' => $directory,
            //    'orphan' => '?',
            $output = drush_format_table($result,false,array('node'=>5,'title' => 20,'filename'=>30,'directory'=>25));

The problem is, that the output is all over the shop, rather than being lined up nicely as it should be.

Where am I going wrong?

  • I prefer using views_data_export to output CSV, and that can be run from drush drush vde.
    – mradcliffe
    Nov 4, 2016 at 15:20
  • Presumably that would mean setting up a View and executing it? I don't think this will work for me, since I need to find <img> tags in the middle of my content, then check if the files exist, then find them in the files table, and then update the corresponding entity so that the "use" of the file is registered. Don't see myself doing that in Views!
    – Martin K
    Nov 4, 2016 at 15:25

1 Answer 1


You are better off sticking with your initial implementation; if you use Drush output formatters, then the end-user will be able to convert your data to csv or yaml or other formats as needed. If it takes a long time to collect your data, then use drush_log or perhaps a progress bar to let the user know something is going on.

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.