[mdlug] [HOWTO request] filter stderrr without altering stdout
Aaron Kulkis
akulkis3 at hotpop.com
Wed Apr 11 08:36:00 EDT 2007
Robert Meier wrote:
> Carl
>
> Thank you for your response.
>
>>> How can I write a wrapper that filters stderr (fd 2) without altering
>>> stdout (fd 1) using ksh?
>
>> I'm not sure I understand what you're trying to do. It sounds
>> like you want a script that will call a function. And I'm guessing
>> that you don't want to see any errors from the function, but not
>> filter errors from the script.
I recall once seeing a method for doing exactly that sort of thing
It involved something like this:
(foo | foo_postprocess ) &2>1 | foo_error_postprocess
It's been about 5 years, so I'll have to play with the syntax
to get it right... when I finally get off duty in another
4 to 8 hours (never know around here....)
>
> Actually I do want to see errors from the function, except for
> a few known errors that have been handled by the script.
>
> Detail:
> # I have an interactive function, part of a large package.
> # It reports to both stdout and stderr
> # Unfortunately, it also reports a warning to stderr even though
> # the warning has been successfully dealt with.
> ksh> echo help | func 1>stdout 2>stderr
> ksh> cat stdout
> This is a nice function that does something interactively.
> ksh> cat stderr
> Warning: Unable to find my config file in /etc/func
> Found the config file in /opt/etc/func
> usage: func ...
>
> # I don't wish to alter stdout at all, so the user can continue
> # normal use.
> # I do want to remove the warning successfully dealt with lest the
> # the user ignore all errors and warnings.
> # I do want the remaining warnings and errors to be seen, so the
> # user can take corrective action.
> ksh> echo help | func-wrapper 1>wrapped-stdout 2>wrapped-stderr
> ksh> cat wrapped-stdout
> This is a nice function that does something interactively.
> ksh> cat wrapped-stderr
> usage: func ...
>
> # The necessary feature is that only a few well-defined warnings
> # be removed from stderr, while all of stdout and the remainder of
> # stderr are passed unaltered.
> ksh> diff stdout wrapped-stdout
> # no difference
> ksh> diff stderr wrapped-stderr
> < Warning: Unable to find my config file in /etc/func
> < Found the config file in /opt/etc/func
>
>
>
> ksh> cat func-wrapper
> #!/bin/sh
> ????
> func $*
> ????
>
> For instance, is there a redirection usage that can carry interactive stdout
> past grep, and apply grep to stderr only?
> THE FOLLOWING DOES NOT WORK AS WRITTEN:
> ksh> cat func-wrapper
> #!/bin/sh
> func $* 1>3 2>1 |
> grep -v 'Warning: Unable to find my config file in /etc/func' |
> grep -v 'Found the config file in /opt/etc/func' |
> cat 1>2 3>1
> THE ABOVE DOES NOT WORK AS WRITTEN
>
> TIA,
More information about the mdlug
mailing list