zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Capturing STDOUT without subshells or file I/O
Date: Mon, 17 Sep 2018 14:20:39 -0700	[thread overview]
Message-ID: <CAH+w=7YiK08_jREimmsA_dtH-J67HrPcGpnbhB8R0GBV0WNfpA@mail.gmail.com> (raw)
In-Reply-To: <CAHYJk3QeRVJkHXcyFcPMKKNQg1A+3qM=1mbXqJTbrjVuE617vA@mail.gmail.com>

On Mon, Sep 17, 2018 at 2:01 PM, Mikael Magnusson <mikachu@gmail.com> wrote:
> On Mon, Sep 17, 2018 at 10:46 PM, Daniel Shahaf <d.s@daniel.shahaf.name> 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.

  reply	other threads:[~2018-09-17 21:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-02 20:57 Ben Klein
2018-09-03  0:40 ` Joey Pabalinas
2018-09-03 14:02 ` Daniel Shahaf
2018-09-03 18:43   ` Joey Pabalinas
2018-09-17 20:13     ` Ben Klein
2018-09-17 20:46       ` Daniel Shahaf
2018-09-17 21:01         ` Mikael Magnusson
2018-09-17 21:20           ` Bart Schaefer [this message]
2018-09-17 21:19       ` dana
2018-09-17 21:33         ` Bart Schaefer
2018-09-18  5:12 ` Sebastian Gniazdowski
2018-09-21  6:58   ` Oliver Kiddle

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='CAH+w=7YiK08_jREimmsA_dtH-J67HrPcGpnbhB8R0GBV0WNfpA@mail.gmail.com' \
    --to=schaefer@brasslantern.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).