From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-users-return-23669-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.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,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 50789a54 for ; Fri, 21 Sep 2018 06:59:20 +0000 (UTC) Received: (qmail 27407 invoked by alias); 21 Sep 2018 06:59:05 -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: 23669 Received: (qmail 24981 invoked by uid 1010); 21 Sep 2018 06:59:05 -0000 X-Qmail-Scanner-Diagnostics: from park01.gkg.net 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(205.235.26.22):SA:0(-1.4/5.0):. Processed in 4.365485 secs); 21 Sep 2018 06:59:05 -0000 X-Envelope-From: SRS0=wpi5=MD=yahoo.co.uk=okiddle@bounces.park01.gkg.net X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Virus-Scanned: by amavisd-new at gkg.net Authentication-Results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1537513102; bh=Yv93mUyGhdM5//n/43jHObJIQEJUZKCgF8WSs2cZBpU=; h=From:References:To:Subject:Date:From:Subject; b=h0dx+k9Z1qrnPlAH3fsmYzOK3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z7zsHq nKL1OXTK4U818oXE6ZgKwPPh2lEBKCAp4l1R4j6jfFYLPsTsa8KJMx_4QqzeJUJvFlBZPxx5Fcwi t7UKyTCNDP2iZrZIQZ9b9mlBqv4Lme.ApJaubW105JExGlSvIMhCBv8EXNWd23OZb6jxvAcNcYYP Th0fPbvwszr2JzavEZI866bynRLLEkjDBjH4o8vrnfSXgH8rNXsQEvkE7jE2esNmPEfY7W83bayB qKDMwcISFqtdhua82tUz1lb3ecpt37IlWW5KB4u3zltsj_rEzPTTu cc: robobenklein@gmail.com, Zsh Users In-reply-to: From: Oliver Kiddle References: <04a12c6a-c926-b088-f386-8a2bdb81dad2@gmail.com> To: Sebastian Gniazdowski Subject: Re: Capturing STDOUT without subshells or file I/O MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <26367.1537512609.1@hydra> Content-Transfer-Encoding: 8bit Date: Fri, 21 Sep 2018 08:58:20 +0200 Message-ID: <26400-1537513100.788869@IMS5.scMb.xe2G> On 18 Sep, Sebastian Gniazdowski wrote: > > I have an interesting predicament, I with to capture the STDOUT (builtin printf) of a ZSH function to a variable, in which the function should be running in the current shell context. > mksh can do this with: > > ${ foo;} > > foo runs in current shell and the ${ ... } is substituted with its > output. I was under the impression that ksh93 does this with the basic $( ... ) syntax meaning that that syntax does not inherently imply the use of a subshell. It depends on whether there are pipes, external commands or only builtins there. For ksh93, they had their own I/O abstraction – sfio – which was a complete replacement for stdio but which made it easy to capture the output instead of writing it. Using sprintf everywhere would be a very invasive change but the open_memstream/temporary file approach used for print -v would work. And in any case, there would be other, bigger, problems to solve. Personally, I can't claim to be have ever been especially concerned about the cost of the fork and was not especially enthused by the addition of -v to print. $(...) substitutions are also run sequentially: echo $SECONDS ; echo $(sleep 1;echo $SECONDS) $(sleep 1;echo $SECONDS) Perhaps I'm forgetting something obvious but at the moment, I can't think why they couldn't be run in parallel - if performance is the concern. Oliver