From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 e3545696 for ; Fri, 16 Aug 2019 10:46:42 +0000 (UTC) Received: (qmail 14836 invoked by alias); 16 Aug 2019 10:46:34 -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: 24150 Received: (qmail 5367 invoked by uid 1010); 16 Aug 2019 10:46:34 -0000 X-Qmail-Scanner-Diagnostics: from st43p00im-zteg10062001.me.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25538. spamassassin: 3.4.2. Clear:RC:0(17.58.63.166):SA:0(-4.3/5.0):. Processed in 4.042603 secs); 16 Aug 2019 10:46:34 -0000 X-Envelope-From: whereislelouch@icloud.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at icloud.com designates 17.58.63.166 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1565952357; bh=1aOh1xVkBdEUMWCAOzoW23ipxvibmLJLvf8K/KCAMQ8=; h=Content-Type:Subject:From:Date:Message-Id:To; b=JQDGHRABijQsIT33zfexjysqNyrbjv5Q1zam7W5KLC5G1QndC6LiWKCxNkapRvdge KwEpv3HjY1J43cURPMCTVyZ+DK4pePFH/BhWfVzpurt/bH7JhKAP/kjbZANM+ddgMx 265dfHHkpa5YDgfPGACtXz87bkAfIv40nEATLBSOpSv8HUh+mr0oTUFYL7wxPXfSyU 68G+VvsDf63dD0ioFQNLis02CSPtZIYbQhgsfTFOBp9isTO/l40/YGa+ibPbWbB0mP x3h0sEFxUlwqKvcC8P5aNXlPSdWMW+FP5P1o5hGr7wtfIdxkOevTUAgPq/jVJGQRNM bJt/aWUYFku6A== Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: Capture stdout, stdin, and exit status in different variables without using temporary files From: Aryn Starr In-Reply-To: <20190816100501.nsvfbdwwnoaihlhe@chaz.gmail.com> Date: Fri, 16 Aug 2019 15:15:49 +0430 Cc: zsh-users@zsh.org Content-Transfer-Encoding: quoted-printable Message-Id: <70382019-1857-4452-85FC-F038D8BBE206@icloud.com> References: <20190816100501.nsvfbdwwnoaihlhe@chaz.gmail.com> To: Stephane Chazelas X-Mailer: Apple Mail (2.3445.104.11) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-08-16_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 mlxscore=0 mlxlogscore=858 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1812120000 definitions=main-1908160112 Thanks! I read those links and reached two conclusions: That I should = this `yash` out. And that I should look for ways to create files on = memory. (I meant stderr, \(=E1=B5=94=E1=B5=95=E1=B5=94)/ ) > On Aug 16, 2019, at 2:35 PM, Stephane Chazelas = wrote: >=20 > I assume you meant stderr and not stdin which would make little > sense. And the bash wiki pages refers to capturing both stdout > and err, not stdin (whatever that means). >=20 > 2019-08-15 20:22:38 +0430, Aryn Starr: >> If not, is a named pipe advantageous to a temporary file? >=20 > With named pipes, you'd get deadlocks unless you use a > select()/poll() loop like for unnamed pipes. >=20 >> Is there a way to avoid disk IO (which will probably slow things down = considerably)? >=20 > To expand on the solution in the link I gave earlier to also > capture the exit status, that would be: >=20 > << > #! /bin/zsh - > zmodload zsh/zselect > zmodload zsh/system >=20 > (){exec {wo}>$1 {ro}<$1} <(:) # like yash's wo>>|ro (but on Linux = only) > (){exec {we}>$1 {re}<$1} <(:) >=20 > # the command (here ls as an example) > ls -d / /x >&$wo 2>&$we & pid=3D$! >=20 > exec {wo}>&- {we}>&- > out=3D err=3D > o_done=3D0 e_done=3D0 >=20 > while ((! (o_done && e_done))) && zselect -A ready $ro $re; do > if ((${#ready[$ro]})); then > sysread -i $ro && out+=3D$REPLY || o_done=3D1 > fi > if ((${#ready[$re]})); then > sysread -i $re && err+=3D$REPLY || e_done=3D1 > fi > done > wait "$pid"; exit_status=3D$? >=20 > printf '%s: %s\n' stdout "$out" stderr "$err" 'exit status' = "$exit_status" >>>=20 >=20 > Which gives: >=20 > stdout: / >=20 > stderr: ls: cannot access '/x': No such file or directory >=20 > exit status: 2 >=20 > (note that in $out and $err, the trailing newline character is > not removed). >=20 > --=20 > Stephane