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: Tue, 22 Feb 2022 09:38:35 +0000 Message-ID: <1280eba0-81c0-6e7b-d512-bbd1f83a409c@posteo.de> References: 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="15006"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Feb 22 10:46:28 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 1nMRka-0003cZ-6A for guile-user@m.gmane-mx.org; Tue, 22 Feb 2022 10:46:28 +0100 Original-Received: from localhost ([::1]:38270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMRkY-0000vb-SZ for guile-user@m.gmane-mx.org; Tue, 22 Feb 2022 04:46:26 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:45408) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMRd3-0006sF-AR for guile-user@gnu.org; Tue, 22 Feb 2022 04:38:41 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:36761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMRd0-0006pd-VY for guile-user@gnu.org; Tue, 22 Feb 2022 04:38:41 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 4C5F8240027 for ; Tue, 22 Feb 2022 10:38:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1645522717; bh=lfh57bBl6eBJW+v3GCe5LTopy75KaRMA6iq7CW0Rjcc=; h=Date:Subject:To:From:From; b=VEsiYn/yM9nnU48c4AdRyxIMxZEt91L4k2z6D/vS5Q+MKBTPkBzSZ9Hdz2hMr5CaN 2MLSPTNZw7CZyxXt+8UV4bMCcgDBaD8q8UFOa1W+h2mKLg/rmATKAr1EvNN/AVX9ZZ ed7Fepap1POzE1YMhgzCp747I1Rxg6ySZMQ4qON4OSx2heaSkMGshDRt8NkNVe5MUz 7iqfVhi2nqjmqe2kKtv+ryE2FRWN4VFCSc9KGzeoM0dsUAw9wakx1Y+XPTHzm9WDUH lEsiwnpu+5AcRQhL2vUdRh7+aP48SY93ahZ3GM6cN2LxEpIl6pkMrzPxmS2J1nsbbg nw7BwujfsLG7g== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4K2vHc0C7tz6tnX for ; Tue, 22 Feb 2022 10:38:35 +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:18116 Archived-At: 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 -- repositories: https://notabug.org/ZelphirKaltstahl