[CM] How to capture standard output of Linux command in s7

Kjetil Matheussen k.s.matheussen at gmail.com
Wed Nov 25 07:50:29 PST 2015


(Sorry about the lack of indentation in previous post)


(define (get-system-output command)
  (let ((logfilename "/tmp/logtemp"))
    (system (string-append command " > " logfilename))
    (let* ((ret "")
           (fd (open-file logfilename "r"))
           (line (read-line fd)))
      (while (not (eof-object? line))
        (set! ret (string-append ret line))
        (set! line (read-line fd)))
      (close fd)
      (system (string-append "rm " logfilename))
      ret)))


On Wed, Nov 25, 2015 at 4:46 PM, Kjetil Matheussen <k.s.matheussen at gmail.com
> wrote:

> Hi,
>
> There might be a better solution, but this is the function I've been using
> to do this:
>
> (define (get-system-output command) (let ((logfilename "/tmp/logtemp")) (system
> (string-append command " > " logfilename)) (let* ((ret "") (fd (open-file
> logfilename "r")) (line (read-line fd))) (while (not (eof-object? line)) (
> set! ret (string-append ret line)) (set! line (read-line fd))) (close fd) (system
> (string-append "rm " logfilename)) ret)))
>
> (this is for guile though, not s7, but you get the idea)
>
>
> On Wed, Nov 25, 2015 at 4:38 PM, JV <billbose at gmail.com> wrote:
>
>> system prints the  output of the command.
>> I cannot save the output with:
>>
>> (define sv (system ("ls"))
>>
>> On Wed, Nov 25, 2015 at 8:02 AM, <bil at ccrma.stanford.edu> wrote:
>>
>>> system is normally included in s7 in Linux -- try
>>> (help system) or (system "ls -la s7.c" #t).  If your
>>> version of s7 was built with the compiler flag
>>> WITH_SYSTEM_EXTRAS set to 0, you can still get at the
>>> c library's system function via libc.scm, but
>>> hopefully that isn't necessary.
>>>
>>>
>>>
>>
>>
>> --
>> Joseph Vijay
>>
>> _______________________________________________
>> Cmdist mailing list
>> Cmdist at ccrma.stanford.edu
>> https://cm-mail.stanford.edu/mailman/listinfo/cmdist
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/mailman/private/cmdist/attachments/20151125/e20e4fb6/attachment.html>


More information about the Cmdist mailing list