guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: easy question: getting shell output?


From: Christopher Cramer
Subject: Re: easy question: getting shell output?
Date: Fri, 26 Apr 2002 11:31:02 -0500
User-agent: Mutt/1.2.5i

On Fri, Apr 26, 2002 at 04:02:26PM +0000, Ciaran O'Riordan wrote:
> I'm having a small problem capturing the output of
> a shell command.
> 
> I want the output of 'ls -1' to be stored in a
> variable which I will later split into a list.
> 
> I've tried the obvious things like changing the
> default output port to a newly created string port
> but no matter what I try the output always gets
> displayed to my terminal.

The default output port is only used by Guile. A separate process
(such as ls) isn't going to use it.

What you probably want is open-input-pipe, e.g.:

(use-modules
    (ice-9 rw)
    (ice-9 popen))

(let (
        (input (open-input-pipe "ls -1"))
        (buffer (make-string 256)))
    (let loop ((l '()))
        (let ((n (read-string!/partial buffer input)))
            (if n
                (loop (cons (substring buffer 0 n) l))
                (apply string-append (reverse! l))))))

-- 
Christopher Cramer <address@hidden> <http://www.pyro.net/~crayc/>
On résiste à l'invasion des armées; on ne résiste pas à l'invasion
des idées.  -- Victor Hugo



reply via email to

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