How can I output a Drush report in table format? 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' =&gt; array(
        'outputformat' =&gt; array(
            'default' =&gt; 'table',
            'pipe-format' =&gt; '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' =&gt; array(
                'node' =&gt; 'Nid',
                'title' =&gt; 'Title',
                'filename' =&gt; 'Filename',
                'directory' =&gt; 'Directory',
            ),
            // In table format, the 'column-widths' item is consulted
            // to determine the default weights for any named column.
            'column-widths' =&gt; array(
                'title' =&gt; 20,
            ),
            'require-engine-capability' =&gt; 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' =&gt; $nid,
                'title' =&gt; $title,
                'filename' =&gt; end($file),
                'directory' =&gt; $directory,
            //    'orphan' =&gt; '?',
            );
            $output = drush_format_table($result,false,array('node'=&gt;5,'title' =&gt; 20,'filename'=&gt;30,'directory'=&gt;25));
            drush_print($output);


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?
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.