Alex Kost <[email protected]>:

> 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

Reply via email to