guile-user
[Top][All Lists]
Advanced

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

Re: Retrieve output from command


From: Kyle Cronan
Subject: Re: Retrieve output from command
Date: Tue, 31 Jul 2001 11:26:00 -0500 (CDT)

On 31 Jul 2001, Manuel Giraud wrote:

>
> I'm trying to get the result of the command "ls" in a list, for
> example :
>         (define l (system->list "ls"))
>

How about this:

(use-modules (ice-9 popen))
(define (system->list command)
   (define (read-lines port results)
      (let ((line (read-line port)))
         (if (eof-object? line)
            results
            (read-lines port (cons line results)))))
   (read-lines (open-input-pipe command) '()))

Regards,
Kyle Cronan
<address@hidden>

> I've tried 'system' but it doesn't work since it returns the exit code
> of the command. Maybe, I will be able to do that using port, but maybe
> there's already a library to do such things.
>
> --
> "Never imagine yourself not to be otherwise than what it might appear
> to others that what you were or might have been was not otherwise than
> what you had been would have appeared to them to be otherwise"
>   The Duchess
>
> _Manuel Giraud_
>
> _______________________________________________
> Guile-user mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/guile-user
>




reply via email to

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