From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: Neil Jerram <neiljerram@gmail.com>,
alex.sassmannshausen@gmail.com, tomas@tuxteam.de
Cc: guile-user <guile-user@gnu.org>
Subject: Re: Shell commands with output to string
Date: Wed, 23 Feb 2022 01:28:58 +0000 [thread overview]
Message-ID: <7fd00d2a-44b0-5f7a-3b70-56de0afaa065@posteo.de> (raw)
In-Reply-To: <CAKuG=vtF121oBgC4VFAgqz_o9Bc5D8=ZedRj3O4RO74iSGPf0A@mail.gmail.com>
Hi all!
On 2/22/22 12:20, Neil Jerram wrote:
> On Tue, 22 Feb 2022 at 10:23, Alex Sassmannshausen
> <alex.sassmannshausen@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)))))))))
I will look at all the ideas and try to get a good picture of it : )
Thank you all for the advice and examples!
Regards,
Zelphir
--
repositories: https://notabug.org/ZelphirKaltstahl
next prev parent reply other threads:[~2022-02-23 1:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 9:29 Shell commands with output to string Zelphir Kaltstahl
2022-02-22 9:38 ` Zelphir Kaltstahl
2022-02-22 10:20 ` Alex Sassmannshausen
2022-02-22 10:43 ` post
2022-02-23 14:01 ` Josselin Poiret
2022-03-08 23:12 ` Zelphir Kaltstahl
2022-03-09 14:14 ` Josselin Poiret
2022-02-22 11:20 ` Neil Jerram
2022-02-23 1:28 ` Zelphir Kaltstahl [this message]
2022-02-23 1:29 ` Zelphir Kaltstahl
2022-02-22 10:21 ` tomas
2022-02-22 14:27 ` Olivier Dion via General Guile related discussions
2022-02-22 16:00 ` Leo Butler
2022-02-22 16:33 ` Olivier Dion via General Guile related discussions
2022-02-23 1:26 ` Zelphir Kaltstahl
2022-02-23 14:13 ` Olivier Dion via General Guile related discussions
2022-02-26 0:32 ` Zelphir Kaltstahl
-- strict thread matches above, loose matches on Subject: below --
2022-02-23 17:48 Blake Shaw
2022-02-23 18:25 ` Olivier Dion via General Guile related discussions
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7fd00d2a-44b0-5f7a-3b70-56de0afaa065@posteo.de \
--to=zelphirkaltstahl@posteo.de \
--cc=alex.sassmannshausen@gmail.com \
--cc=guile-user@gnu.org \
--cc=neiljerram@gmail.com \
--cc=tomas@tuxteam.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).