From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-users-return-23652-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 2e2eaf63 for ; Mon, 17 Sep 2018 21:21:11 +0000 (UTC) Received: (qmail 13933 invoked by alias); 17 Sep 2018 21:20:49 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23652 Received: (qmail 988 invoked by uid 1010); 17 Sep 2018 21:20:49 -0000 X-Qmail-Scanner-Diagnostics: from mail-lf1-f50.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.167.50):SA:0(-1.9/5.0):. Processed in 3.472115 secs); 17 Sep 2018 21:20:49 -0000 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=IxR60vp4VfdSJL53pprLZLFdGYRDzvg4kMDUB1B/nds=; b=kNV8gebcga+krNMLhOze3uXOa+E4i2c/S3KJ0h0uTIrc9E5yOwMaBUInoYZOk3hsjz 9wNNqb6hQw1HgtkUghagBrJpOQieuHB/zg5r/HUMn+2bfB0Ifxw07hC1h3jEwfa/e5m/ uWHzdSxg2RyH9Egt30uceqijN/OEXC5E7+7jgkc8uLCCInhBnDY5GKtW/WXcQ8Ltj6bY /6RCDUQS4uAfoY0MIYb09LR1a90+LaMQRauqkcdp1MiKYwGrkI9n1kpBq+rIMX3F+wRn gu0Tsgu2eRx2bVdQ8kiEGVPisZ0zj3Q6V67du2RZHRP/WZBsdEs2KxTnj1Iry8DjO+uT AliQ== X-Gm-Message-State: APzg51CkRtBnIm9t6olZjwm+yiiJo7QdsqYn9rfbA1eI4hbZ2UitGKB4 xRsxIIOBx5Pcm/X9bqe2AtkpHV71M8Xy4yBhHkWQA4rFbc8xjg== X-Google-Smtp-Source: ANB0VdY7lFJKwccqhq8uIwbdqgj22c3y3eIcHXJ7X67SgeQ/JQnNRbVWak7lkiu/db5Ku8cm98bItCDZm4GS5GGtoF4= X-Received: by 2002:a19:5353:: with SMTP id h80-v6mr18155492lfb.9.1537219239994; Mon, 17 Sep 2018 14:20:39 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <04a12c6a-c926-b088-f386-8a2bdb81dad2@gmail.com> <20180903140214.76kbzgpfru6atc5u@tarpaulin.shahaf.local2> <20180903184353.yzujt7ywnlvufeye@gmail.com> <1537217203.28092.1511309952.71C4C11C@webmail.messagingengine.com> From: Bart Schaefer Date: Mon, 17 Sep 2018 14:20:39 -0700 Message-ID: Subject: Re: Capturing STDOUT without subshells or file I/O To: Zsh Users Content-Type: text/plain; charset="UTF-8" On Mon, Sep 17, 2018 at 2:01 PM, Mikael Magnusson wrote: > On Mon, Sep 17, 2018 at 10:46 PM, Daniel Shahaf 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.