From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Josselin Poiret Newsgroups: gmane.lisp.guile.user Subject: Re: Shell commands with output to string Date: Wed, 23 Feb 2022 15:01:46 +0100 Message-ID: <87czjdn0l1.fsf@jpoiret.xyz> References: <1280eba0-81c0-6e7b-d512-bbd1f83a409c@posteo.de> <87tucryzdg.fsf@gmail.com> <6d1232e036287a4cc7994d9fac5fceec@thomasdanckaert.be> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3108"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Zelphir Kaltstahl , guile-user@gnu.org To: post@thomasdanckaert.be, alex.sassmannshausen@gmail.com Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Feb 23 15:06:59 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nMsIF-0000ak-7g for guile-user@m.gmane-mx.org; Wed, 23 Feb 2022 15:06:59 +0100 Original-Received: from localhost ([::1]:45326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMsIE-0006gf-8K for guile-user@m.gmane-mx.org; Wed, 23 Feb 2022 09:06:58 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:44448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMsDK-0001QN-KU for guile-user@gnu.org; Wed, 23 Feb 2022 09:01:54 -0500 Original-Received: from jpoiret.xyz ([206.189.101.64]:51162) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMsDH-0007a3-0N for guile-user@gnu.org; Wed, 23 Feb 2022 09:01:54 -0500 Original-Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 28484183B03; Wed, 23 Feb 2022 14:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1645624907; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bK4rqfhbSF9lmCrLC65QpEthECffUN7xs1ye7B+NqRs=; b=FkgaOpkyyfCz7kozRkKl2vOZmQhxk3Il9yIAPrY0WAyY3rV2+OdL8pHabBeGjoD5eYtZG5 ApoG4ZoK+NR6lrj0FilvWhGG0iyoveYqdPZq8wbZFMj2JLdhJnbk3mZaZ/qj9WBnF0UZ2z pJtpoT59jUtuiPFuk3yFAIJjTpIt0mqTvE9wNtrFSpUec+ZwCN/5NggvFl74nW4B3sT+QW 6z507AEYtNU6S60rvdXtQvN3nW0JVR3dXKkPRgmPfvuhAvmEnajzs8eHVrezJwByVcKFT/ SK0eK1JO21LDCrcx9Xqi8L0iD1Ie2CwebvJMNrLB1cjgamhIdRw85gdjeD30cQ== In-Reply-To: <6d1232e036287a4cc7994d9fac5fceec@thomasdanckaert.be> Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spamd-Bar: + Received-SPF: pass client-ip=206.189.101.64; envelope-from=dev@jpoiret.xyz; helo=jpoiret.xyz X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.499, PDS_OTHER_BAD_TLD=1.997, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18131 Archived-At: Hello, post@thomasdanckaert.be writes: > Hi, > > to throw in an example: I once used a function like the one below to > handle stdout and stderr from external commands (from > https://github.com/tdanckaert/jobview/blob/master/jobtools.scm#L38 ). > Probably far from perfect (my first and only scheme project...), but > hopefully it gives you an idea. Just chiming in to say that [1] isn't fixed yet, so you may run into issues if you try to redirect out and err to the same port. In Guix, we use the following workaround for now ([2]): --8<---------------cut here---------------start------------->8--- (match-let (((input . output) (pipe))) ;; Hack to work around Guile bug 52835 (define dup-output (duplicate-port output "w")) ;; Void pipe, but holds the pid for close-pipe. (define dummy-pipe (with-input-from-file "/dev/null" (lambda () (with-output-to-port output (lambda () (with-error-to-port dup-output (lambda () (apply open-pipe* (cons "" command))))))))) (close-port output) (close-port dup-output) (handler input) (close-port input) (close-pipe dummy-pipe)) --8<---------------cut here---------------end--------------->8--- [1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=52835 [2] https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/installer/utils.scm?id=c0bc08d82c73e464a419f213d5ae5545bc67e2bf#n87 Best, -- Josselin Poiret