From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.user Subject: Re: Shell commands with output to string Date: Tue, 22 Feb 2022 11:20:03 +0000 Message-ID: References: <1280eba0-81c0-6e7b-d512-bbd1f83a409c@posteo.de> <87tucryzdg.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10502"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: alex.sassmannshausen@gmail.com Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Feb 22 12:20:33 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nMTDd-0002bM-CB for guile-user@m.gmane-mx.org; Tue, 22 Feb 2022 12:20:33 +0100 Original-Received: from localhost ([::1]:48654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMTDc-0007uy-Ch for guile-user@m.gmane-mx.org; Tue, 22 Feb 2022 06:20:32 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:39346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMTDO-0007tf-Kj for guile-user@gnu.org; Tue, 22 Feb 2022 06:20:18 -0500 Original-Received: from [2607:f8b0:4864:20::229] (port=38631 helo=mail-oi1-x229.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nMTDL-0006l7-TL for guile-user@gnu.org; Tue, 22 Feb 2022 06:20:18 -0500 Original-Received: by mail-oi1-x229.google.com with SMTP id y7so14038441oih.5 for ; Tue, 22 Feb 2022 03:20:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HKVHZt+MrDCCjtcV0go2Zn5SUdncTVxl+n/4qM1xNU8=; b=QUdkoqqpDqHG5qqx4C6BZ7NPVAbcqISU+T1Iqq8W71qPXJxfNyuFM1txYhTUE6NhhW CxOyHJyXDfJV8RO7JZInySKAalMNJDpvtlaAvBqITKX0CuSye8YtyCedsgzH/IiFb66E TuXCK1zCJe99Ajehbkys1YzIlpJz3RTcF7ANtFUFTx7S5ruHqDeZvaaP7nU2p+3uTTtz QKsG56sZURju4mmsj0Kgid3Ja6J4aQCHk6XTIMP4A3CX83hT/aRE6RYSEeFUA7vUS4Rc VDKkX27fh64AUH2tzjGZFzmyQnE+hAuoohvx6DENxcAG15P6RAInMfDCIeR2I+iD0gZS wZFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HKVHZt+MrDCCjtcV0go2Zn5SUdncTVxl+n/4qM1xNU8=; b=Tx+UuPnkJtCauU957791YGbEBqUplzI2+qRDcgSC8Wv7zyKbnYJAzYAu9QRRft61By HDfAtPhhBJTw2lYzUMPMVKZo/tWbaqH54aYjU6n8tgn26YXC/KakqGiNnNuJwU4hwRmp C1vXQ0czVBIoYSmTTwwNX++SxXpQGVyuFu2dW57Vbfte1DKmPAdZPc/JVVLZod5krOHO CaIr2AS2A2Ukgn4xAAM0OfjNnQsZ40+Q1ihcx++cm9uLTWTX86N5yAVudvTZqCao+yuH U6kgvIT/Rpvm4mthVNd/XqKHwY9pEbPtHwdR40FmvVpW/Xi7G0iAQ2BgOu9hf01ihnTX blJg== X-Gm-Message-State: AOAM53177RBB8UuH7sclOjc4WR+lh0hD0z6EJqVRMS7Zzn/dw3XuMhAy XRfwKsAPKGIBEyDWdYf5bS5juOZWUlk+3cFkYck= X-Google-Smtp-Source: ABdhPJxAbSLvU/ZiPYkcCzL8JLwehRO/Hf66qTHIVBskZ8vrtqw7MdJMYcGMgtQMso5XqoUMZuDMN7gTPNdP6AZ+xJU= X-Received: by 2002:a05:6808:19a5:b0:2d4:edeb:9beb with SMTP id bj37-20020a05680819a500b002d4edeb9bebmr1613036oib.279.1645528814426; Tue, 22 Feb 2022 03:20:14 -0800 (PST) In-Reply-To: <87tucryzdg.fsf@gmail.com> X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::229 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::229; envelope-from=neiljerram@gmail.com; helo=mail-oi1-x229.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18120 Archived-At: On Tue, 22 Feb 2022 at 10:23, Alex Sassmannshausen 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)))))))))