From: Marko Rauhamaa <marko@pacujo.net>
To: Alex Kost <alezost@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: How to do "ls /tmp > /dev/null" in Guile?
Date: Sat, 19 Mar 2016 13:02:36 +0200 [thread overview]
Message-ID: <87zitulohf.fsf@elektro.pacujo.net> (raw)
In-Reply-To: <87zituzs6d.fsf@gmail.com> (Alex Kost's message of "Sat, 19 Mar 2016 13:19:06 +0300")
Alex Kost <alezost@gmail.com>:
> Hello, in the guile REPL I evaluated the following:
>
> (with-output-to-port (%make-void-port "w")
> (lambda () (display "foo") (newline)))
>
> and I got no output as expected. Then I tried the following:
>
> (with-output-to-port (%make-void-port "w")
> (lambda () (system* "ls" "/tmp")))
>
> but there was an output from "ls" command. So my question is: how to
> get rid of this output?
When you use ports (which the operating system knows nothing about),
Guile needs to actively jockey the data between them.
(use-modules (ice-9 popen))
(with-output-to-port (%make-void-port "w")
(lambda ()
(let ((output (open-input-pipe "ls /tmp")))
(let loop ()
(let ((c (read-char output)))
(if (not (eof-object? c))
(begin
(write-char c)
(loop)))))
(close-input-port output))))
Marko
next prev parent reply other threads:[~2016-03-19 11:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-19 10:19 How to do "ls /tmp > /dev/null" in Guile? Alex Kost
2016-03-19 11:02 ` Marko Rauhamaa [this message]
2016-03-20 8:32 ` Alex Kost
2016-03-20 9:23 ` Marko Rauhamaa
2016-03-21 9:40 ` Alex Kost
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=87zitulohf.fsf@elektro.pacujo.net \
--to=marko@pacujo.net \
--cc=alezost@gmail.com \
--cc=guile-user@gnu.org \
/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).