guile-user
[Top][All Lists]
Advanced

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

Re: Shell commands with output to string


From: Josselin Poiret
Subject: Re: Shell commands with output to string
Date: Wed, 23 Feb 2022 15:01:46 +0100

Hello,


post@thomasdanckaert.be writes:

> Hi,
>
> to throw in an example: I once used a function like the one below to 
> handle stdout and stderr from external commands (from 
> https://github.com/tdanckaert/jobview/blob/master/jobtools.scm#L38 ).  
> Probably far from perfect (my first and only scheme project...), but 
> hopefully it gives you an idea.

Just chiming in to say that [1] isn't fixed yet, so you may run into
issues if you try to redirect out and err to the same port.  In Guix, we
use the following workaround for now ([2]):
--8<---------------cut here---------------start------------->8---
  (match-let (((input . output) (pipe)))
    ;; Hack to work around Guile bug 52835
    (define dup-output (duplicate-port output "w"))
    ;; Void pipe, but holds the pid for close-pipe.
    (define dummy-pipe
      (with-input-from-file "/dev/null"
        (lambda ()
          (with-output-to-port output
            (lambda ()
              (with-error-to-port dup-output
                (lambda ()
                  (apply open-pipe* (cons "" command)))))))))
    (close-port output)
    (close-port dup-output)
    (handler input)
    (close-port input)
    (close-pipe dummy-pipe))
--8<---------------cut here---------------end--------------->8---

[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=52835
[2] 
https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/installer/utils.scm?id=c0bc08d82c73e464a419f213d5ae5545bc67e2bf#n87

Best,
-- 
Josselin Poiret



reply via email to

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