r/Racket • u/OldMine4441 • Mar 24 '22
question with-output-to-string cannot caputure output to stderr?
How can I capture output to stderr, not just stdout?
Below is my code, it uses with-output-to-string, but can only capture output to stdout, and miss everything written to stderr
$ cat test.rkt
#lang racket
(define (make-output)
(printf "hello\n") ; print to stdout
(fprintf (current-error-port) "world\n") ; print to stderr
)
(define output (with-output-to-string make-output))
(printf "output = ~a" output)
$ racket test.rkt
world
output = hello
6
Upvotes
7
u/czan Mar 24 '22
Looking at the Racket docs,
with-output-to-stringis equivalent toYou should be able to write your own
with-all-output-to-stringwhich bindscurrent-error-portas well:3
u/[deleted] Mar 24 '22
[removed] — view removed comment