lilypond-user
[Top][All Lists]
Advanced

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

Re: Read multiple lines from an input-pipe


From: Urs Liska
Subject: Re: Read multiple lines from an input-pipe
Date: Wed, 30 Apr 2014 09:49:54 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

Am 29.04.2014 13:26, schrieb Urs Liska:
Am 29.04.2014 12:24, schrieb Urs Liska:
Hi all,

I'm writing a set of functions to retrieve Git repository information
for use in a score:
https://github.com/openlilylib/snippets/tree/master/editorial-tools/git-commands



I'm using a function provided by Lars Haulin in a comment to a blog post
that is essentially the one for open-input-pipe given here:
https://www.gnu.org/software/guile/manual/html_node/Pipes.html

In addition to what is already there I want to write commands that use
more than one line of the Git commands' output (e.g. print the whole
commit message).
How would I approach that in Scheme?
What I need is for example a list of all strings that the command
outputs.
Do I have to write some kind of loop while the pipe is open?
Or is there a way to get the whole output as one string or a list of
strings?

Well, RTFM at least gives a start:
Using read-delimited instead of read-line returns the complete output in
one string.

And using (string-split git-function-name #\newline)
provides me with a list of strings.

Next step to find out will be to process this list of strings to a
usable markup function ...

Urs


I've tried around for quite some time now to no avail, probably having tried _everything_ except the right solution ;-) so I have to come back here and ask.

I now have this implementation:

#(use-modules (ice-9 popen))
#(use-modules (ice-9 rdelim))

#(define (strsystem_internal cmd)
   (let* ((port (open-input-pipe cmd))
          (str (read-delimited "" port)))
     (close-pipe port)
     str))

#(define-markup-command (gitCommand layout props cmd) (markup?)
   (let* ((result (string-split
                   (strsystem_internal (string-append "git " cmd))
                   #\newline)))
   (interpret-markup layout props
     (car result))))

If I feed it a command returning multiple lines, e.g.

\gitCommand "status"

this will create a markup with the first line of "git status"' result.

What way do I have to go to return either a \markuplist with all the lines or a number of \markups, one for each line? If the command's result has only one line the function should only return a single \markup. And it shouldn't hickup when the result is empty (i.e.. only an "eof-object?").

Thanks for any suggestions.
Urs




reply via email to

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