Racket equivalent of /dev/null?
Asked Answered
L

1

7

If I have a function that prints to (current-output-port), is there an easy way to run the function without it printing to the output port?

Previously, I've used /dev/null as an output target:

(with-output-to-file "/dev/null" #:exists 'append
  (lambda () (displayln "hello world")))

This is easy, but platform dependent. Also I'll sometimes forget the #:exists flag.

Linettelineup answered 13/12, 2015 at 1:40 Comment(0)
L
7

Yes! Use open-output-nowhere from racket/port.

(parameterize ([current-output-port (open-output-nowhere)])
  (displayln "hello world"))

If you want to hide error output, override current-error-port instead / also.

Linettelineup answered 13/12, 2015 at 1:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.