Joseph Tam
2015-Mar-19 00:37 UTC
Patch for "doveadm -f table" nit (was Re: Dovecot current number of connections being used.)
> doveadm who -1 2>/dev/null | wc -lYou have to redirect stderr to /dev/null because that's where the first header line is written to. The default format style (table) is inconsistent with the other formats (flow,pager,tab) that write headers and data to stdout. The following patch will pick this nit. This patch will require modifications to scripts that rely on doveadm writing headers to stderr. For example, the above doveadm command could be modified to doveadm who -1 | grep -vc '^username' -------------------------------------------------------------------------------- --- a/dovecot-2.2.16.rc1/src/doveadm/doveadm-print-table.c Wed Mar 18 15:40:40 2015 +++ b/dovecot-2.2.16.rc1/src/doveadm/doveadm-print-table.c Wed Mar 18 15:41:18 2015 @@ -151,3 +151,3 @@ for (i = 0; i < count; i++) { - if (i > 0) fprintf(stderr, " "); + if (i > 0) printf(" "); @@ -155,3 +155,3 @@ DOVEADM_PRINT_HEADER_FLAG_RIGHT_JUSTIFY) == 0) { - fprintf(stderr, "%-*s", (int)headers[i].length, + printf("%-*s", (int)headers[i].length, headers[i].title); @@ -158,3 +158,3 @@ } else { - fprintf(stderr, "%*s", (int)headers[i].length, + printf("%*s", (int)headers[i].length, headers[i].title); @@ -162,3 +162,3 @@ } - fprintf(stderr, "\n"); + printf("\n"); } -------------------------------------------------------------------------------- Joseph Tam <jtam.home at gmail.com>
Timo Sirainen
2015-Mar-19 00:49 UTC
Patch for "doveadm -f table" nit (was Re: Dovecot current number of connections being used.)
On 19 Mar 2015, at 02:37, Joseph Tam <jtam.home at gmail.com> wrote:> > >> doveadm who -1 2>/dev/null | wc -l > > You have to redirect stderr to /dev/null because that's where the > first header line is written to. The default format style (table) > is inconsistent with the other formats (flow,pager,tab) that write > headers and data to stdout. > > The following patch will pick this nit. This patch will require > modifications to scripts that rely on doveadm writing headers to stderr. > For example, the above doveadm command could be modified to > > doveadm who -1 | grep -vc '^username'There's no reason why flow and pager should write headers to stderr because it would always result only in a mess. But instead of changing table headers to write to stdout, I think a better fix would be to make tab formatter write headers to stderr. Including headers in stdout makes it more difficult to write scripts that access the actual data. For example now you can do "doveadm who -1 | sort" and the output will work. If headers were written to stdout you'd have to make it more complicated. Also you can now easily specify what you want to do with the headers, 2>/dev/null if you don't care about them or 2>&1 if you want to include them in stdout (which works even after |sort). So, I'll add in my v2.3 TODO that tab formatter should write to stderr..
Joseph Tam
2015-Mar-19 01:01 UTC
Patch for "doveadm -f table" nit (was Re: Dovecot current number of connections being used.)
On Thu, 19 Mar 2015, Timo Sirainen wrote:>> You have to redirect stderr to /dev/null because that's where the >> first header line is written to. The default format style (table) >> is inconsistent with the other formats (flow,pager,tab) that write >> headers and data to stdout. > > There's no reason why flow and pager should write headers to stderr > because it would always result only in a mess.Right.> But instead of changing table headers to write to stdout, I think a > better fix would be to make tab formatter write headers to stderr.That would at least make the behaviour consistent.> Including headers in stdout makes it more difficult to write scripts > that access the actual data. For example now you can do "doveadm who > -1 | sort" and the output will work. If headers were written to stdout > you'd have to make it more complicated. Also you can now easily > specify what you want to do with the headers, 2>/dev/null if you don't > care about them or 2>&1 if you want to include them in stdout (which > works even after |sort).I agree with the easier parsing thing for scripts. It just a little weird when you're doing piping interactively and the header pops out. Another option is to add another flag/formatter that will squelch headers. I'm cool with whatever you implement. Joseph Tam <jtam.home at gmail.com>
Gedalya
2015-Mar-19 08:30 UTC
Patch for "doveadm -f table" nit (was Re: Dovecot current number of connections being used.)
On 03/18/2015 08:49 PM, Timo Sirainen wrote:> There's no reason why flow and pager should write headers to stderr because it would always result only in a mess. But instead of changing table headers to write to stdout, I think a better fix would be to make tab formatter write headers to stderr. Including headers in stdout makes it more difficult to write scripts that access the actual data. For example now you can do "doveadm who -1 | sort" and the output will work. If headers were written to stdout you'd have to make it more complicated. Also you can now easily specify what you want to do with the headers, 2>/dev/null if you don't care about them or 2>&1 if you want to include them in stdout (which works even after |sort). > > So, I'll add in my v2.3 TODO that tab formatter should write to stderr..I've been using "-f flow fetch text | sed s/^text=//" when training spamassasin. Couldn't find a straightforward 'fetch raw message'. Seems unnecessarily awkward. Moving headers to stderr would help this, though.
Seemingly Similar Threads
- Patch for "doveadm -f table" nit (was Re: Dovecot current number of connections being used.)
- Patch for "doveadm -f table" nit (was Re: Dovecot current number of connections being used.)
- How about an option to disbale headers? (was Re: Patch for "doveadm -f table" nit)
- How about an option to disbale headers? (was Re: Patch for "doveadm -f table" nit)
- Dovecot current number of connections being used.