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: Shell commands with output to string Date: Tue, 22 Feb 2022 09:29:37 +0000 Message-ID: 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="18666"; mail-complaints-to="usenet@ciao.gmane.io" To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Feb 22 10:30:59 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 1nMRVb-0004dN-6D for guile-user@m.gmane-mx.org; Tue, 22 Feb 2022 10:30:59 +0100 Original-Received: from localhost ([::1]:56210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMRVZ-0001oi-UF for guile-user@m.gmane-mx.org; Tue, 22 Feb 2022 04:30:57 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMRUO-0001oa-Lq for guile-user@gnu.org; Tue, 22 Feb 2022 04:29:44 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:59567) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMRUM-0005In-NG for guile-user@gnu.org; Tue, 22 Feb 2022 04:29:44 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 312B9240028 for ; Tue, 22 Feb 2022 10:29:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1645522179; bh=73xw601BXZkHj+pPOtswVu20rIl6xI9wk61LEX6T6fs=; h=Date:To:From:Subject:From; b=XLEVap/R2arvnDWpq6e2EBSAc+OfUdRdFVU4slAElduISSixLg+C0WkV1C16TpfMm YyzXzM+dzWskblUacO7hKeBfCiLZOjtdaPCOYjr6SiF2fwVt4BndJEJEkZso1F4rBB 5JOve73wgjE4IWtN6i1H+lzPhT699Bf0oEa54ZhRwnbf+XOkXXZctKNc8AnCzd6hva H7GjWxMUEoZ5i8RT6B5rS5v5mUk1+qfAVa/eXAY2H/SVV+kC2ovk6xa8tgeqw/ZUzv 8tNy4qWmdPuxTYHE8xnQYKnutlpdnGb42Tl9jW28mH7JzPfHlPwoiqJxMz7buwbQcs w5TyHN5cDxU/A== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4K2v5G3xtQz6tnb for ; Tue, 22 Feb 2022 10:29:38 +0100 (CET) Content-Language: en-US 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:18115 Archived-At: 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 -- repositories: https://notabug.org/ZelphirKaltstahl