unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Josselin Poiret <dev@jpoiret.xyz>
To: post@thomasdanckaert.be, alex.sassmannshausen@gmail.com
Cc: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>, guile-user@gnu.org
Subject: Re: Shell commands with output to string
Date: Wed, 23 Feb 2022 15:01:46 +0100	[thread overview]
Message-ID: <87czjdn0l1.fsf@jpoiret.xyz> (raw)
In-Reply-To: <6d1232e036287a4cc7994d9fac5fceec@thomasdanckaert.be>

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	other threads:[~2022-02-23 14:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-22  9:29 Shell commands with output to string Zelphir Kaltstahl
2022-02-22  9:38 ` Zelphir Kaltstahl
2022-02-22 10:20   ` Alex Sassmannshausen
2022-02-22 10:43     ` post
2022-02-23 14:01       ` Josselin Poiret [this message]
2022-03-08 23:12         ` Zelphir Kaltstahl
2022-03-09 14:14           ` Josselin Poiret
2022-02-22 11:20     ` Neil Jerram
2022-02-23  1:28       ` Zelphir Kaltstahl
2022-02-23  1:29     ` Zelphir Kaltstahl
2022-02-22 10:21   ` tomas
2022-02-22 14:27 ` Olivier Dion via General Guile related discussions
2022-02-22 16:00   ` Leo Butler
2022-02-22 16:33     ` Olivier Dion via General Guile related discussions
2022-02-23  1:26       ` Zelphir Kaltstahl
2022-02-23 14:13         ` Olivier Dion via General Guile related discussions
2022-02-26  0:32           ` Zelphir Kaltstahl
  -- strict thread matches above, loose matches on Subject: below --
2022-02-23 17:48 Blake Shaw
2022-02-23 18:25 ` Olivier Dion via General Guile related discussions

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87czjdn0l1.fsf@jpoiret.xyz \
    --to=dev@jpoiret.xyz \
    --cc=alex.sassmannshausen@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=post@thomasdanckaert.be \
    --cc=zelphirkaltstahl@posteo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).