This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Pipe behavior clarification?

On 1/23/2017 9:32 AM, Eric Blake wrote:
On 01/22/2017 04:23 PM, Eliot Moss wrote:
On 1/22/2017 3:19 PM, David Balažic wrote:

Is this a correct pipe behavior?

$ echo booo | tee >(md5sum --tag) >/dev/null
MD5 (-) = 9c8b79bdf79ef0ee73a77b8d36d27a2d

$ echo booo | tee >(md5sum --tag) | cat >/dev/null

Here's what I think happens, even if it is a bit counter-intuitive:

(...) creates a subprocess, whose input comes from some kind
of pipe or socket, and tee is presented with a filename it can
use to write to that socket.

The *output* of the >(...) subprocess is hooked up to what is
known to be the output of tee *at the time the subprocess is
created*.  This happens *before* any > redirections are done.

Rather, all >() and > redirections are performed in left-to-right order.
 But you are correct that the second >/dev/null is overwriting the
stdout that was originally given by >(md5sum), and therefore tee is NOT
writing to the md5sum process.

However, in the case of the | pipe, that plumbing is set up
*before* the >(...) construct is acted on.

Also correct. Mixing >() and | is usually not what you want, as you are
no longer writing to the pipeline.

Note that you could do >(md5sum --tag >whatever) if you want
to specifically control the output of md5sum.

I am sure someone more knowledgeable will correct me if I've
missed anything important here :-) ...

You got the gist of it.  Order matters, and specifying more than one
stdout (by any mix of >, >(), or |) is generally not what you want.

Dear Eric (et al.) -- I *mostly* agree with this, with the exception
that >(...) is *not* an output redirection.  It will present tee with
the name of a file -- either a named pipe or a /dev/fdnnn file name.
By experimentation I discovered that this particular replacement
is not done in the same left-to-right pass as I/O redirections ...

Regards - EM

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]