On Tue, 22 Feb 2022 at 10:23, Alex Sassmannshausen <alex.sassmannshau...@gmail.com> wrote: > > Hi Zelphir, > > I think you want to be using the popen / pipe procedures for this. See > https://www.gnu.org/software/guile/docs/docs-2.2/guile-ref/Pipes.html > for the chapter in the manual.
Another example, for reading transactions out of a Ledger file: (use-modules (ice-9 popen)) (define (ledger-transactions filename account payee commodity year) (let* ((cmd (string-append "ledger -f " filename)) (cmd-add! (lambda strings (set! cmd (apply string-append cmd " " strings))))) (if payee (cmd-add! "-l 'payee=~/" payee "/'")) (if year (cmd-add! "--begin " (number->string year) " --end " (number->string (1+ year)))) (cmd-add! "reg") (if account (cmd-add! account)) (cmd-add! "-F '(\"%(format_date(date, \"%Y-%m-%d\"))\" \"%P\" \"%(t)\")\n'") (let ((p (open-input-pipe cmd))) (let loop ((txs '())) (let ((tx (read p))) (if (eof-object? tx) (reverse! txs) (begin (if commodity (set-car! (cddr tx) (string-replace-substring (caddr tx) commodity ""))) (loop (cons tx txs)))))))))