Broken process substitution

Eric Blake eblake@redhat.com
Fri Aug 13 20:18:00 GMT 2010


On 08/13/2010 02:04 PM, Daniel Colascione wrote:
> Try "echo hello > >(cat)" -- that's supposed to output "hello".

What makes you think it's supposed to echo hello?  That's system
specific on what will happen.  According to the bash manual,

>(cat)

is evaluated first, and will result in a /dev/fd reference, or a named
pipe (it so happens that it is a /dev/fd reference in cygwin).  But this
pipe is tied to the subprocess, so it only exists as long as the
subprocess exists.

Then bash does the redirection.  If >(cat) has already gone away, then
the resulting string /dev/fd/63 no longer exists.  So redirecting to a
non-existent file fails.  But if cat hasn't finished executing yet, then
the redirection will succeed.

Classic data race.  Your expectations are wrong, and this is not a bug
in cygwin, per se.

On the other hand, a named fifo might be more persistent; bash might
keep the fifo around until the entire statement is complete, rather than
keeping the pipe and /dev/fd reference for the life of the subprocess.
But I'd have to recompile bash to force it to use a named fifo, and we
already know that named fifos have bugs in cygwin.

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20100813/868287b7/attachment.sig>


More information about the Cygwin mailing list