unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* capture stdout and stderr
@ 2018-05-24  8:10 Thomas Danckaert
  2018-05-26 10:24 ` Catonano
       [not found] ` <CAGua6m1qMCrO_iFpxPiD1pM8FopkyMo4ypCeQ6F5rCCixyPFMQ@mail.gmail.com>
  0 siblings, 2 replies; 5+ messages in thread
From: Thomas Danckaert @ 2018-05-24  8:10 UTC (permalink / raw)
  To: guile-user

Hi Guilers,

I want to run an external process, and capture both its stdout and 
stderr output streams.  I didn't find an easy way to get a port for 
an external process' stderr, other than wrapping the call to the 
process in "with-error-to-port".

My questions are:
  0) Did I miss something obvious? :)
  1) why doesn't the second approach in the code below work (the 
output-string is always empty)?
  2) are there any other (better) solutions?
  3) I suppose my approach with (pipe) might block if the process 
writes too much data to stderr before I read from the pipe. Should I 
use "select" to interleave reads from stdout and stderr?

thank you!

Thomas

(use-modules (ice-9 format)
	     (ice-9 popen)
	     (ice-9 textual-ports))

(define (run-command)
   (let ((process (open-input-pipe "./stdoutstderr.sh")))
     (format #t "stdout: '~a'~%" (get-string-all process))
     (close-pipe process)))

;; Works:
(let ((err-pipe (pipe)))
   (with-error-to-port (cdr err-pipe) run-command)

   (close-port (cdr err-pipe))
   (format #t "stderr: '~a' ~%" (get-string-all (car err-pipe))))

;; Doesn't work: (get-output-string) returns empty string.
(let ((err-port (open-output-string)))
   (with-error-to-port err-port run-command)

   (format #t "stderr: '~a'~%" (get-output-string err-port))
   (close-output-port err-port))



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-05-29 17:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-24  8:10 capture stdout and stderr Thomas Danckaert
2018-05-26 10:24 ` Catonano
2018-05-26 11:40   ` Thomas Danckaert
     [not found] ` <CAGua6m1qMCrO_iFpxPiD1pM8FopkyMo4ypCeQ6F5rCCixyPFMQ@mail.gmail.com>
2018-05-27 17:26   ` Thomas Danckaert
2018-05-29 17:35     ` Catonano

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).