From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Re: Shell commands with output to string Date: Wed, 23 Feb 2022 01:28:58 +0000 Message-ID: <7fd00d2a-44b0-5f7a-3b70-56de0afaa065@posteo.de> References: <1280eba0-81c0-6e7b-d512-bbd1f83a409c@posteo.de> <87tucryzdg.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27651"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: Neil Jerram , alex.sassmannshausen@gmail.com, tomas@tuxteam.de Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Feb 23 02:29:24 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 1nMgT6-0006zQ-N7 for guile-user@m.gmane-mx.org; Wed, 23 Feb 2022 02:29:24 +0100 Original-Received: from localhost ([::1]:34414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMgT5-00044y-Ak for guile-user@m.gmane-mx.org; Tue, 22 Feb 2022 20:29:23 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:38122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMgSn-000444-Bg for guile-user@gnu.org; Tue, 22 Feb 2022 20:29:05 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:60263) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMgSl-0004k4-2Y for guile-user@gnu.org; Tue, 22 Feb 2022 20:29:05 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 6A2A5240026 for ; Wed, 23 Feb 2022 02:29:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1645579740; bh=MykQ5scib3iChkq80NSdNMJRvCMcT/2H9qsXU49UCqA=; h=Date:Subject:To:Cc:From:From; b=RXvfuQslkKsIib6+OW26zw95kjaahdV0S2MVfvl4ikL6lMEvPG1BahyNUsFNNaLhv 89v4ROyYV4zdf7qGx/4EgGYWPVQrbqp2SItP0oZCdsFDPpiei7klKm1PKti1pTimTM QdD6blpHSafmrR+Y5/myl/NZgXZzQJV2b44ozaJJ3s65JWw0em/tcyDBWB7epLn5wH OD+zosLUZ7U2vLsG25CXrjABzSKbk7UyLQDwJCLoFpbUQllGMSLygLP5z5bQIEZSNr axn5PFl+OuhSaGp//ofj+1o4Rbp8PBUyp2kSNb/1g0rWcjXA3W6P6XjKvF5dSWl5JF 1pa24AXmQrO+Q== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4K3JNC1Rrbz6tmM; Wed, 23 Feb 2022 02:28:59 +0100 (CET) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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:18126 Archived-At: Hi all! On 2/22/22 12:20, Neil Jerram wrote: > 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))))))))) 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