From: Bart Schaefer <schaefer@brasslantern.com>
To: Han Pingtian <hanpt@linux.vnet.ibm.com>, zsh-users@zsh.org
Subject: Re: Is it possible to capture stdout and stderr to separate variables in Zsh?
Date: Sun, 09 Sep 2012 12:18:02 -0700 [thread overview]
Message-ID: <120909121802.ZM17393@torch.brasslantern.com> (raw)
In-Reply-To: <20120901115937.GC1777@localhost.localdomain>
On Sep 1, 7:59pm, Han Pingtian wrote:
}
} I'm using zsh 5.0, but looks like still cannot close the prior coproc
} with "coproc exit":
}
} % coproc while read line;do print -r -- "$line:u";done
This is a bug/misfeature that I think I've mentioned before (possibly
only on zsh-workers) which affects built-in commands including loop
constructs.
The trouble is that zsh opens the coproc descriptors in the parent
shell (as it must) and marks them close-on-exec. It then forks for
the actual coprocess job and dups the coproc descriptors to the job's
stdin and stdout.
Then the bug happens: Because the coprocess is a built-in, there is
no exec, so the original coproc descriptors are never closed. This
leaves the coprocess "talking to itself":
zsh 17133 schaefer 0r FIFO 0,7 2256774 pipe
zsh 17133 schaefer 1w FIFO 0,7 2256773 pipe
zsh 17133 schaefer 2u CHR 136,2 4 /dev/pts/2
zsh 17133 schaefer 10u CHR 136,2 4 /dev/pts/2
zsh 17133 schaefer 11r FIFO 0,7 2256773 pipe
zsh 17133 schaefer 14w FIFO 0,7 2256774 pipe
Note that 14w is connected to 0r and 11r is connected to 1w, all in
the same process. IIRC exactly the same thing happens in at least
some revisions of ksh if you use a built-in construct as a coproc.
The workaround for now is to close the coproc inside the coproc:
% coproc { coproc exit; while read line;do print -r -- "$line:u";done }
next prev parent reply other threads:[~2012-09-09 19:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-06 8:09 Nikolai Weibull
2012-03-06 17:16 ` Philippe Troin
2012-03-07 7:01 ` Bart Schaefer
2012-03-07 9:26 ` Nikolai Weibull
2012-03-08 14:53 ` Bart Schaefer
2012-03-30 7:15 ` Nikolai Weibull
2012-03-30 14:49 ` Bart Schaefer
2012-09-10 6:16 ` Han Pingtian
2012-03-07 19:37 ` Philippe Troin
2012-03-08 4:56 ` Bart Schaefer
2012-09-01 11:59 ` Han Pingtian
2012-09-09 19:18 ` Bart Schaefer [this message]
2012-08-31 0:40 ` Paul Maisano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=120909121802.ZM17393@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=hanpt@linux.vnet.ibm.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).