[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to do "ls /tmp > /dev/null" in Guile?
From: |
Marko Rauhamaa |
Subject: |
Re: How to do "ls /tmp > /dev/null" in Guile? |
Date: |
Sat, 19 Mar 2016 13:02:36 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Alex Kost <address@hidden>:
> 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