bash strerr pipe problem - workaround ?
dave selby
dave6502 at googlemail.com
Sat Jun 14 08:37:01 UTC 2008
2008/6/14 James Gray <james at gray.net.au>:
>
> On 14/06/2008, at 6:16 PM, dave selby wrote:
>> I have a app that outputs to stderr, what I need is a filtered version
>> to be saved in a file
>>
>> motion -c %s/core/motion_conf/motion.conf 2> saved
>>
>> works as expected but is unfiltered. So to filter it I am trying ...
>>
>> motion -c %s/core/motion_conf/motion.conf | grep -E 'error|not
>> found' > saved
>
> Hi Dave :)
>
> Yep - because by the time you're redirecting STDERR to "saved", the
> output has already been sent to /dev/stderr (usually the screen). The
> key is to remember that with shell redirection, ORDER IS IMPORTANT ;)
>
> Try something like this:
>
> motion -c %s/core/motion_conf/motion.conf 2>&1 | egrep 'error|not
> found' > saved
That what I need - works a treat. I could not think how to redirect
stderr to stdout, many thanks :)
> The magic is the "2>&1" which tells the shell, send STDERR to the same
> place as STDOUT. As pipes (in the example above) read from STDIN, by
> redirecting STDERR->STDOUT we can then pipe the error stream as
> normal :)
>
> Consider this:
>
> some_command > output.file 2>&1
>
> STDOUT is going to a file called "output.file", we then redirect
> STDERR to the same place as STDOUT which means we merge the streams
> into a single output file. However, the following WILL NOT WORK AS IT
> FIRST APPEARS:
That makes sense too
> some_command 2>&1 > output.file
>
> Think about it ;) .... and read the "REDIRECTION" section in "man
> bash".
>
> HTH,
>
> James
Thanks James for explaining this, that sorts my problem
cheers
Dave
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
--
Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
More information about the ubuntu-users
mailing list