From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Timothy Sample Newsgroups: gmane.lisp.guile.user Subject: Re: Questions about (open-input-output-pipe Date: Wed, 11 Nov 2020 12:32:13 -0500 Message-ID: <87k0urre8y.fsf@ngyro.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31746"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cc: guile-user To: luhux Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Nov 11 18:32:35 2020 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 1kctz1-00089W-7K for guile-user@m.gmane-mx.org; Wed, 11 Nov 2020 18:32:35 +0100 Original-Received: from localhost ([::1]:47992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kctz0-0003FI-5z for guile-user@m.gmane-mx.org; Wed, 11 Nov 2020 12:32:34 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kctym-0003F2-Li for guile-user@gnu.org; Wed, 11 Nov 2020 12:32:20 -0500 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]:36745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kctyi-0000n6-L2 for guile-user@gnu.org; Wed, 11 Nov 2020 12:32:20 -0500 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id EA8F35C00FE; Wed, 11 Nov 2020 12:32:13 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 11 Nov 2020 12:32:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=ccUQSK8JJYUKgvUf0GbwTW2PncTGeWkGJxp8NWOEJ o4=; b=dV0XjErgZMrWmQZL8jMshyif5pBkGSEP2cm0QRFChlDGvYUA1Bow60qF/ YK2m5r7RAS1hPaKoPZcraaj89MFS8ndOUOtXsbYxgbGx9aaB6JSBBMPm94qLoHHr m3VewPgNgWBaxTyOgi2qICJTSyU5DWmIqNkyd0icNP5VqwLvokNzgkxOiMwEowFY 95p8CRe/vrYlS/OSzrgtzYJi4N5NRZdfd09m7gzcWUrFkUO55zQXzkO/wf30JteV EIy0yEgVygmQ8+wH6DcnTLvdI8IH8xb2xw1aQ+XvL63JLH4TwvaLDEm9ubZJ4siz N0IRKjv6waj0f/Ab33UwX8+C7TALA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedruddvtddggedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufhfffgjkfgfgggtgfesthhqredttderjeenucfhrhhomhepvfhimhho thhhhicuufgrmhhplhgvuceoshgrmhhplhgvthesnhhghihrohdrtghomheqnecuggftrf grthhtvghrnhepieduuefhgeegleelveehgedugfeuhfeikefftdevieelgfelhfdvtdfg ieehtefgnecukfhppeejgedrudduiedrudekiedrgeegnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepshgrmhhplhgvthesnhhghihrohdrtgho mh X-ME-Proxy: Original-Received: from mrblack (74-116-186-44.qc.dsl.ebox.net [74.116.186.44]) by mail.messagingengine.com (Postfix) with ESMTPA id 892543280066; Wed, 11 Nov 2020 12:32:13 -0500 (EST) In-Reply-To: (Neil Jerram's message of "Tue, 10 Nov 2020 14:27:34 +0000") Received-SPF: pass client-ip=66.111.4.28; envelope-from=samplet@ngyro.com; helo=out4-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/11 12:32:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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:17016 Archived-At: Hi luhux, Neil Jerram writes: > On Tue, 10 Nov 2020 at 08:51, luhux wrote: > >> I want to implement this shell command: >> >> wg pubkey < private > public >> >> [...] >> >> I implemented it using the following code in guile: >> >> [...] >> >> (define (wg-gen-public-key private-key) >> (let ((port (open-input-output-pipe "wg pubkey"))) >> (display private-key port) >> (let ((result (read-line port))) >> (close-port port) >> result))) >> >> but the code [gets] stuck [...] >> >> How should I do? > > I guess it's because "wg pubkey" has not yet seen EOF on its input, i.e. = it > doesn't know that the input is complete. > > If that's right, I'm afraid I don't know how to fix it. Presumably you > need a call that closes half of the port, but still allows reading the "wg > pubkey" output from it. You can use the new =E2=80=9Cpipeline=E2=80=9D interface: (define (wg-gen-public-key private-key) (call-with-values (lambda () (pipeline '(("wg" "pubkey")))) (lambda (from to pids) (display private-key to) (close-port to) (let ((result (read-line from))) (close-port from) ;; Reap the process and check its status. (match-let* (((pid) pids) ((_ . status) (waitpid pid))) (unless (zero? (status:exit-val status)) (error "could not generate public key"))) result)))) It gives you two ports, =E2=80=9Cfrom=E2=80=9D and =E2=80=9Cto=E2=80=9D, as= if you called =E2=80=9Cpipe=E2=80=9D and then forked and exec=E2=80=99ed. Hence, you can close the =E2=80=9Cto=E2= =80=9D port to let =E2=80=9Cwg=E2=80=9D know there=E2=80=99s no more input coming. (BTW, if you use this code dire= ctly, don=E2=80=99t forget to use the =E2=80=9C(ice-9 match)=E2=80=9D module for = =E2=80=9Cmatch-let*=E2=80=9D.) As far as I know, there is no way to close half of the =E2=80=9Copen-pipe= =E2=80=9D port. I think that =E2=80=9COPEN_BOTH=E2=80=9D is useful if you have a =E2=80=9Cc= o-process=E2=80=9D that implements some protocol. That way, it knows it needs to respond immediately whenever it finishes reading a protocol-defined message (after every S-expression, for example). Hope that helps! -- Tim