[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Shell commands with output to string
From: |
Olivier Dion |
Subject: |
Re: Shell commands with output to string |
Date: |
Tue, 22 Feb 2022 09:27:57 -0500 |
On Tue, 22 Feb 2022, Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> 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)
I use the following:
(define-module (shell utils)
#:use-module (ice-9 format)
#:use-module (ice-9 popen)
#:use-module (ice-9 textual-ports))
(define (shell% proc fmt . args)
(let* ((port (open-input-pipe (format #f "~?" fmt args)))
(output (proc port)))
(close-pipe port)
output))
(define-public (shell . args)
(apply shell% (cons get-string-all args)))
(define-public (shell$ . args)
(apply shell% (cons get-line args)))
Then
(shell "ls" "-l")
The $ variant is to get a single line in the output.
--
Olivier Dion
Polymtl
Re: Shell commands with output to string,
Olivier Dion <=