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:29:29 +0000 Message-ID: <3afc645f-3e27-bd38-6a22-280579ec72c3@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: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33385"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user@gnu.org To: alex.sassmannshausen@gmail.com Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Feb 23 02:30:32 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 1nMgUC-0008Vw-DS for guile-user@m.gmane-mx.org; Wed, 23 Feb 2022 02:30:32 +0100 Original-Received: from localhost ([::1]:35738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMgUB-0004yP-FU for guile-user@m.gmane-mx.org; Tue, 22 Feb 2022 20:30:31 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:38206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMgTH-0004xL-3k for guile-user@gnu.org; Tue, 22 Feb 2022 20:29:36 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:55479) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMgTE-0004oD-Ez for guile-user@gnu.org; Tue, 22 Feb 2022 20:29:34 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id C65B9240026 for ; Wed, 23 Feb 2022 02:29:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1645579770; bh=pvRAe/lOGPfp2FhOSXeC+xJeX8EV2rediccJIYmDKmE=; h=Date:Subject:To:Cc:From:From; b=nGP1mmNFxJugl+akq4d/OEo7ho1nwhJOOrNaYlm29q4yPg4uWRac8ogFBvuki2Vzl FnTXzY5yvMo6vulxPftvrVUQruVeXLXFZeu5ngBoCEOaM4i0bidV9Mah/ULbyKDbpr 7h4b0KJ208hCGVzPEpzaKaQ8D+TN0d7EXpdEkSYKGFH9lIjWgv/SqtSlE4Vi/YiI53 9ca2qOoncz4j4BdocZp2wAKz13c4FD4GsvLN6SSMl7H2Ss1pfxeuhBjIUp174MKM1h 2erru7/SQJleDjY400RwjoxdM7vbJa5Vay7MxxB89nhcrTAR3TG14BiCGcosREH8vb kab95dutb5VKA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4K3JNp2F1Pz9rxD; Wed, 23 Feb 2022 02:29:30 +0100 (CET) Content-Language: en-US In-Reply-To: <87tucryzdg.fsf@gmail.com> 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:18127 Archived-At: Hi Alex! On 2/22/22 11:20, 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. > > Hope this helps :) > > Alex > > Zelphir Kaltstahl writes: > >> Corrections below. >> >> On 2/22/22 10:29, Zelphir Kaltstahl wrote: >>> Hello Guile users! >>> >>> How would I run a shell command from inside Guile and get its output >>> as a string, instead of the output being outputted directly? (Guile >>> 3.0.8) >>> >>> So far I have found >>> >>> ~~~~ >>> (system ...) >>> ~~~~ >>> >>> which I tried to use with >>> >>> ~~~~ >>> scheme@(guile-user)> (with-output-to-string >>>   (system "ls -al")) >>> >>> ;; lots of output immediately shown and not stored in variable >>> >>> ice-9/boot-9.scm:1685:16: In procedure raise-exception: >>> Wrong type to apply: 0 >>> >>> Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue. >>> scheme@(guile-user) [1]> ,bt >>> In ice-9/ports.scm: >>>     476:4  2 (with-output-to-string 0) >>> While executing meta-command: >>> In procedure frame-local-ref: Argument 2 out of range: 1 >>> ~~~~ >>> >>> But this does not give me a string back. >>> >>> I also tried with >>> >>> ~~~~ >>> scheme@(guile-user)> (call-with-values (lambda () (system "ls -al")) >>> ... (lambda (exit-code output) output)) >>> >>> ;; lots of output immediately shown >>> >>> ice-9/boot-9.scm:1685:16: In procedure raise-exception: >>> Wrong number of values returned to continuation (expected 2) >>> >>> Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue. >>> >>> scheme@(guile-user) [1]> ,bt >>> In current input: >>>     10:29  1 (_) >>> In ice-9/boot-9.scm: >>>   1685:16  0 (raise-exception _ #:continuable? _) >>> ~~~~ >>> >>> Is there another function I should be using? >>> >>> I would like to have the exit code and the output of a command. >>> >>> Best regards, >>> Zelphir >> Of course I should use `with-output-to-string` correctly: >> >> ~~~~ >> scheme@(guile-user)> (with-output-to-string >> (lambda () (system "ls -al"))) >> ;; directly outputted stuff >> $1 = "" >> ~~~~ >> >> But still not a win. >> >> Regards, >> Zelphir Thanks for that! Regards, Zelphir -- repositories: https://notabug.org/ZelphirKaltstahl