[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] stdout and stderr to two different process substitutions

From: Bob Proulx
Subject: Re: [Help-bash] stdout and stderr to two different process substitutions
Date: Wed, 25 Jan 2012 00:25:04 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

Peng Yu wrote:
> prog >(gzip > xxx.gz) 2>(gzip > yyy.gz)
> I'm trying to direct stdin and stdout to two different process
> substitutions. But the syntax of 2> does not work.  Does anybody know
> a way to do so? Thanks!

Neither does your above example work.  If you try it with just the
first part you will find out that it isn't working there either.

  $ prog >(gzip > xxx.gz)

If you check xxx.gz you will find that it never has any data.

Put an echo statement in the front to see what is happening.

  $ echo prog >(gzip > xxx.gz)
  prog /dev/fd/62

Unless your program is doing something with a file argument then that
is all that it is to the program.  A file argument.  There isn't a
redirection to it there yet.

The <(list) and >(list) forms create named file pipes and those names
are substituted on the command line.  If you have a command that reads
from a file such as cat, grep, awk then it will read the filename.  If
you want to redirect to or from it then you need to additionally
redirect to or from it.

  $ prog > >(gzip > xxx.gz)

And understanding that should make understanding how to file desriptor
number 2, stderr, into a process too.

  $ prog > >(gzip > xxx.gz) 2> >(gzip > yyy.gz)

Here is a real example that can be cut and pasted for illustration.

  $ { echo STDOUT ; echo STDERR 1>&2 ;} > >(gzip > stdout.gz) 2> >(gzip > 

  $ ls -ldog std*.gz
  -rw-rw-r-- 1 20 Jan 25 00:18 stderr.gz
  -rw-rw-r-- 1 20 Jan 25 00:18 stdout.gz

  $ zcat stdout.gz

  $ zcat stderr.gz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]