[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to do "ls /tmp > /dev/null" in Guile?
From: |
Alex Kost |
Subject: |
Re: How to do "ls /tmp > /dev/null" in Guile? |
Date: |
Mon, 21 Mar 2016 12:40:43 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Marko Rauhamaa (2016-03-20 12:23 +0300) wrote:
> 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.
(close-pipe) is what I needed, thanks! For the record here is the procedure:
(define (system-no-output* . args)
"Like 'system*' but suppress the output of the command indicated by ARGS."
(let ((port (apply open-pipe* OPEN_READ args)))
(read-string port)
(close-pipe port)))
>> 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.
Thanks for the info! There are things to think about.
--
Alex