guile-user
[Top][All Lists]
Advanced

[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: Sun, 20 Mar 2016 11:23:49 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Alex Kost <address@hidden>:

> 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."
>   ???)

Replace (close-input-port) with (close-pipe); that should give you the
exit status. Also you don't need to copy the data to a dummy port if you
only want to ignore it.

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

The diagnostic output (stderr) is a different story. You want to be sure
to want to ignore it. To implement that properly, you should go
lower-level with operating system calls (fork, exec, waitpid). Simply
open "/dev/null" for writing and dup the file descriptor into the slots
1 and 2 of the child process.


Marko



reply via email to

[Prev in Thread] Current Thread [Next in Thread]