Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Capturing STDOUT without subshells or file I/O
- X-seq: zsh-users 23652
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Capturing STDOUT without subshells or file I/O
- Date: Mon, 17 Sep 2018 14:20:39 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=IxR60vp4VfdSJL53pprLZLFdGYRDzvg4kMDUB1B/nds=; b=e/F1Klel27gYOSQ4vA42SHDF4CuJAfg0NYWCZ/Wwd4dYDc+gAjAEDtdPneoWOm0/pg SKqGreIb55A5+NdnmZtgTXDv1R4qJIbkMJeBc0YiaZfpHZsv1fo5VjLB4nJrjLgEtU32 Fw+yMyDpxNmiLRfkE9ZHVtL26wtyXP7w5Z8o97pULjWPfdGj2uO5dGkwEV4VmOqoNlsq ZJ6xhhFL6DaBzAZdtOzcAWsuYoC86NP3SAJbe2EYb+eoGNCcfqRMdG5cYWf7Y7aTeQlG OGKiys6PdbvcE6uwd5FsX81KX75hnkd5Wfz11qidJGiOkL2wAJUOewNbu0ay6sHDemx5 XlUQ==
- In-reply-to: <CAHYJk3QeRVJkHXcyFcPMKKNQg1A+3qM=1mbXqJTbrjVuE617vA@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <04a12c6a-c926-b088-f386-8a2bdb81dad2@gmail.com> <20180903140214.76kbzgpfru6atc5u@tarpaulin.shahaf.local2> <20180903184353.yzujt7ywnlvufeye@gmail.com> <cd8bc7e0-7ae1-8c94-8dea-9b529b2a8fb2@gmail.com> <1537217203.28092.1511309952.71C4C11C@webmail.messagingengine.com> <CAHYJk3QeRVJkHXcyFcPMKKNQg1A+3qM=1mbXqJTbrjVuE617vA@mail.gmail.com>
On Mon, Sep 17, 2018 at 2:01 PM, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> On Mon, Sep 17, 2018 at 10:46 PM, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>>
>> If you could call pipe(2), you'd be able to do
>> .
>> printf foo >&$w
>> read bar <&$r
>> .
>> without forking (where $r,$w were returned by pipe(2)).
>
> That's just a deadlock-by-design.
To expand upon that a bit, the pipe created by the system has a
limited (and generally indeterminate) amount of buffer space, so if
the print side ever sends more than that amount of data at once, it
will block forever, and the read side will never get a chance to
execute. This is WHY (printf '%.2f' "3.4" | read var) creates a
subshell on the left, so that the read and write are simultaneous and
independent.
You could safely do it if you only wrote and read one byte at a time,
but you're not going to pull that off with printf and formatting.
If zsh exposed a way to make the writes non-blocking, you could do it
without deadlock but with possible data loss, but that's not going to
help you with zsh 5.1 and earlier.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author