guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Shell commands with output to string


From: Zelphir Kaltstahl
Subject: Shell commands with output to string
Date: Tue, 22 Feb 2022 09:29:37 +0000

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]