From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alex Sassmannshausen Newsgroups: gmane.lisp.guile.user Subject: Re: Shell commands with output to string Date: Tue, 22 Feb 2022 11:20:32 +0100 Message-ID: <87tucryzdg.fsf@gmail.com> References: <1280eba0-81c0-6e7b-d512-bbd1f83a409c@posteo.de> Reply-To: alex.sassmannshausen@gmail.com Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1536"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.6.10; emacs 27.2 Cc: guile-user@gnu.org To: Zelphir Kaltstahl Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Feb 22 11:23:27 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 1nMSKN-0000Cz-FF for guile-user@m.gmane-mx.org; Tue, 22 Feb 2022 11:23:27 +0100 Original-Received: from localhost ([::1]:59400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMSKM-0008Fz-De for guile-user@m.gmane-mx.org; Tue, 22 Feb 2022 05:23:26 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:53844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMSJz-0008Dj-6m for guile-user@gnu.org; Tue, 22 Feb 2022 05:23:04 -0500 Original-Received: from [2a00:1450:4864:20::52c] (port=36623 helo=mail-ed1-x52c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nMSJx-0005HY-7E for guile-user@gnu.org; Tue, 22 Feb 2022 05:23:02 -0500 Original-Received: by mail-ed1-x52c.google.com with SMTP id cm8so26111947edb.3 for ; Tue, 22 Feb 2022 02:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:user-agent:from:to:cc:subject:date:reply-to:in-reply-to :message-id:mime-version; bh=/7toEh+6nfViwfnN+L3w1A4jwieIGcvOAYFrCs0gsrs=; b=qiWGQwighBYMA790+HzJYMo98sm1/h+lsaVcXIw1dOIHYtJnLoTYCivVIrDIYlFkBw 5YM3R9yeEihESPZY14kbZNetNstJA4W6LH2yZwe7Z6Z1HGEdVSHXZCcdEgZmjJgWVWMm om0ZDiKCOxXgAAjPY5g/ZX9GQvfL3YQZaWkmAqCFULrSVSsyeVBdU1oQG1C0GCbKXCgw LLAp52s+LSaTciw1V4wOyvJ75lVGsaOpkvccO7f9dSO+vO1hXprgoHxQiO7D39NQo63q fBVaxqr5cMVJcAjYMl6h1loJP56Pm2cnwjzl7OaejDSMg9zKHOF2/ZOMyPBmbQCyv/xG BJHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:references:user-agent:from:to:cc:subject:date :reply-to:in-reply-to:message-id:mime-version; bh=/7toEh+6nfViwfnN+L3w1A4jwieIGcvOAYFrCs0gsrs=; b=wUwlxtlIJLKyRbpO7qpetKV4cYhtD98ml8bQj7EJv875zi1KCPr1Acl/V1S82qwZf4 cuMRc9eWUKuwRagQkC75y89Kz458BdGwjMqUja4WwQ7uerKXGgljzFPeG5IPev0zsN/m NBZ3oPH1krFOCfBnoX26KqJoXpVHNlCAsLEZu0wZUEX3+kPq60AD/lv3rv3CnYG1AtBk 0y9imjou3wfoPkq/N+/t43i/EAQ1sqhxENqP6BmBwu2en4ncfaj094uaCYqj7em32Qog u0ATLm/RCr/lwq+gcAK8Byb/kCmq/YFE3ZJs1i8zgfo2dorymfdY4TYCxLolNe1ZoDEC RNOw== X-Gm-Message-State: AOAM533NgobZXULWPyeeytgQZQoNB9cdLhCAHqpKG/3CYdgAgEaoSv6V 9xixdS7/RDFqyXLsDI+LybxESI19IW8= X-Google-Smtp-Source: ABdhPJzUUbjPUvk7EJ4Jy0PNa8TpS1FKkCYajQHDrWuHQD4zYedHVNlN7Gn3NeMarVKjlG96iSD7Ng== X-Received: by 2002:a05:6402:26cf:b0:413:1741:eeab with SMTP id x15-20020a05640226cf00b004131741eeabmr6315685edd.442.1645525378323; Tue, 22 Feb 2022 02:22:58 -0800 (PST) Original-Received: from lilith (77.109.114.104.adsl.dyn.edpnet.net. [77.109.114.104]) by smtp.gmail.com with ESMTPSA id l8sm6028725ejp.198.2022.02.22.02.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 02:22:57 -0800 (PST) In-reply-to: <1280eba0-81c0-6e7b-d512-bbd1f83a409c@posteo.de> X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::52c (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=alex.sassmannshausen@gmail.com; helo=mail-ed1-x52c.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:18118 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 >> =C2=A0 (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.=C2=A0 Type `,bt' for a backtrace or `,q' to conti= nue. >> scheme@(guile-user) [1]> ,bt >> In ice-9/ports.scm: >> =C2=A0=C2=A0=C2=A0 476:4=C2=A0 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.=C2=A0 Type `,bt' for a backtrace or `,q' to conti= nue. >> >> scheme@(guile-user) [1]> ,bt >> In current input: >> =C2=A0=C2=A0=C2=A0 10:29=C2=A0 1 (_) >> In ice-9/boot-9.scm: >> =C2=A0 1685:16=C2=A0 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 =3D "" > ~~~~ > > But still not a win. > > Regards, > Zelphir --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iJUEAREIAD0WIQSaK0Ae0AEGUBWEuqyLxPRHboqOAAUCYhS5ax8cYWxleC5zYXNz bWFubnNoYXVzZW5AZ21haWwuY29tAAoJEIvE9Eduio4AWDIA/2ewTqY/hA8kMkrm cemq67CRxuOVUzNu8xR+HMeagYRlAPwP5PI2ptn5dB31AHHjgo2jedkwcPku36yT lkyQEjOpyg== =rn0y -----END PGP SIGNATURE----- --=-=-=--