Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Is it possible to capture stdout and stderr to separate variables in Zsh?
- X-seq: zsh-users 17243
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Han Pingtian <hanpt@xxxxxxxxxxxxxxxxxx>, zsh-users@xxxxxxx
- Subject: Re: Is it possible to capture stdout and stderr to separate variables in Zsh?
- Date: Sun, 09 Sep 2012 12:18:02 -0700
- In-reply-to: <20120901115937.GC1777@localhost.localdomain>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CADdV=Mtbszh2NjtB8yFjfeo9PR1U7XV-Qi2AQMXCZ0Ag0VTS+w@mail.gmail.com> <1331054185.27052.19.camel@air.fifi.org> <120306230111.ZM11639@torch.brasslantern.com> <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 }
Messages sorted by:
Reverse Date,
Date,
Thread,
Author