unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Neil Jerram <neiljerram@gmail.com>
To: luhux <luhux@outlook.com>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: Questions about (open-input-output-pipe
Date: Tue, 10 Nov 2020 14:27:34 +0000	[thread overview]
Message-ID: <CAKuG=vuNj49S_9xnv6jtRayVFPPB07VAbSkw9+yZZqnkAvKEZg@mail.gmail.com> (raw)
In-Reply-To: <PSXP216MB0214A54B8933A76967AC3E20A0E90@PSXP216MB0214.KORP216.PROD.OUTLOOK.COM>

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.

Alternatively, it might be buffering, i.e. the private key hasn't yet
reached "wg pubkey".  In that case (force-output port) might help.

Best wishes,
    Neil


On Tue, 10 Nov 2020 at 08:51, luhux <luhux@outlook.com> wrote:

> Hello everyone
>
> I am a newbie to guile and I am learning to use guile to write scripts
>
> I want to implement this shell command:
>
>
> wg pubkey < private > public
>
>
>
> This is a command to generate a key,
> It inputs private key and EOF from stdin, then it outputs the public key
> and exits.
>
> I implemented it using the following code in guile:
>
>
>
> (use-modules (ice-9 popen)
>              (ice-9 rdelim))
>
> (define (wg-gen-private-key)
>   (let* ((port (open-input-pipe "wg genkey"))
>         (result (read-line port)))
>     (close-pipe port)
>     result))
>
> (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)))
>
>
> Then I executed the code to get the public key
>
>
>
>
> scheme@(guile-user)> (wg-gen-public-key (wg-gen-private-key))
>
>
>
>
> but the code got stuck in this place:
>
>
>
>
>     (let ((result (read-line port)))
>
>
>
>
> How should I do?
>
> There are too few Guile information on the Internet. Sorry for asking such
> a basic question.
>
> luhux
>
>


  reply	other threads:[~2020-11-10 14:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-10  8:29 Questions about (open-input-output-pipe luhux
2020-11-10 14:27 ` Neil Jerram [this message]
2020-11-11 17:32   ` Timothy Sample

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKuG=vuNj49S_9xnv6jtRayVFPPB07VAbSkw9+yZZqnkAvKEZg@mail.gmail.com' \
    --to=neiljerram@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=luhux@outlook.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).