help-bash
[Top][All Lists]
Advanced

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

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


From: Peng Yu
Subject: Re: [Help-bash] stdout and stderr to two different process substitutions
Date: Wed, 25 Jan 2012 12:36:24 -0600

On Wed, Jan 25, 2012 at 10:04 AM, Greg Wooledge <address@hidden> wrote:
> On Wed, Jan 25, 2012 at 09:50:35AM -0600, Peng Yu wrote:
>> > pipe A leads to gzip, whose stdout goes to the file xx.gz.  Special pipe
>> > B leads to tee, which writes a copy of the piped input to the file yy,
>> > and another copy of the piped input to the screen (foo's stderr).
>>
>> This looks a little wired to me. I though that the last "2" refers to
>> the stderr of tee, but it actually refers to the stderr of the main
>> process?
>
> tee inherits stderr from the script, *before* the script's stderr is
> redirected to the special pipe.  So writing to tee's stderr is basically
> writing to the script's stderr before it gets modified.
>
>> Note: I'm a little confused whether it should be tee's stdout or the
>> main stdout. It seems to be tee's stdout, as I don't see any output
>> from
>>
>>  { echo STDOUT ; echo STDERR 1>&2 ;} > >(gzip > xx.gz) 2> >(tee yy)
>>
>> But this sees to be asymmetric, why tee's stdout is redirected to the
>> main stderr but not tee' stderr?
>
> First, let's observe what it actually does:
>
> imadev:~$ cat yy
> STDERR
> imadev:~$ zcat xx.gz
> STDOUT
> STDERR
>
> The only explanation which can account for that behavior is that the
> process substitutions are not all done at the same time.
>
>  foo > >(gzip) 2> >(tee)
>      ^  ^       ^  ^
>      |  |       |  |
>      2  1       4  3
>
> It appears that each process substitution is done immediately before its
> accompanying redirection.  In order 1 2 3 4 as shown in the diagram.
>
> So, foo's (the script's) stdout has already been redirected (step 2) at
> the time the process substitution for tee is performed (step 3).  Which
> means tee inherits the modified stdout, and the pristine stderr.

OK. To summarize concisely, it appears to be that there are only
"global" stdout and stderr, but stdin is local.

foo  > >(gzip > xx.gz) 2> >(tee yy 1>&2)

-- 
Regards,
Peng



reply via email to

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