unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Alex Kost <alezost@gmail.com>
To: Marko Rauhamaa <marko@pacujo.net>
Cc: guile-user@gnu.org
Subject: Re: How to do "ls /tmp > /dev/null" in Guile?
Date: Sun, 20 Mar 2016 11:32:11 +0300	[thread overview]
Message-ID: <87bn691rec.fsf@gmail.com> (raw)
In-Reply-To: <87zitulohf.fsf@elektro.pacujo.net> (Marko Rauhamaa's message of "Sat, 19 Mar 2016 13:02:36 +0200")

Marko Rauhamaa (2016-03-19 14:02 +0300) wrote:

> 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))))

Ah, thanks!  I get it.  But I also want to check an exit status of the
running command (sorry, that I didn't mention it).  So I would like to
have the following procedure:

(define (system-no-output* . args)
  "Like 'system*' but suppress the output of the command indicated by ARGS."
  ???)

Or even better (it would be a perfect solution for me) the following macro:

(define-syntax-rule (with-no-process-output body ...)
  "Run BODY and suppress all output of the executed sub-processes."
  ???)

So that I could do something like this:

(with-no-process-output
  (let ((status1 (system* "ls" "/tmp"))
        (status2 (system* "ls" "/foo")))
    (format #t "Very useful info: ~a, ~a~%" status1 status2)))

and there would be no standard/error output from both "ls" calls.  Is it
possible?

-- 
Alex



  reply	other threads:[~2016-03-20  8:32 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
2016-03-20  8:32   ` Alex Kost [this message]
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=87bn691rec.fsf@gmail.com \
    --to=alezost@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=marko@pacujo.net \
    /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).