diff --git a/pkgs/racket-doc/scribblings/reference/port-buffers.scrbl b/pkgs/racket-doc/scribblings/reference/port-buffers.scrbl index 455c96416e..cf0fc38fd8 100644 --- a/pkgs/racket-doc/scribblings/reference/port-buffers.scrbl +++ b/pkgs/racket-doc/scribblings/reference/port-buffers.scrbl @@ -43,10 +43,12 @@ one byte is read for @racket[read-bytes-avail!*], buffered bytes, but no further bytes are read. In addition, the initial current output and error ports are -automatically flushed when @racket[read], @racket[read-line], +automatically flushed when they are terminal ports (see +@racket[terminal-port?]) and when @racket[read], @racket[read-line], @racket[read-bytes], @racket[read-string], etc., are performed on the -initial standard input port; more precisely, flushing is performed by -the default port read handler (see @racket[port-read-handler]). +initial standard input port. (More precisely, instead of +@racket[read], flushing is performed by the default port read handler; +see @racket[port-read-handler].) @defproc[(flush-output [out output-port? (current-output-port)]) void?]{ diff --git a/racket/src/cs/schemified/io.scm b/racket/src/cs/schemified/io.scm index 96e3883afe..27ec9c04a7 100644 --- a/racket/src/cs/schemified/io.scm +++ b/racket/src/cs/schemified/io.scm @@ -11890,8 +11890,12 @@ (lambda (in_0) (if (eq? in_0 (unsafe-place-local-ref cell.1$9)) (begin - (1/flush-output (unsafe-place-local-ref cell.2$2)) - (1/flush-output (unsafe-place-local-ref cell.3))) + (if (1/terminal-port? (unsafe-place-local-ref cell.2$2)) + (1/flush-output (unsafe-place-local-ref cell.2$2)) + (void)) + (if (1/terminal-port? (unsafe-place-local-ref cell.3)) + (1/flush-output (unsafe-place-local-ref cell.3)) + (void))) (void)))) (define do-read-bytes! (lambda (who_0 in_0 bstr_0 start_0 end_0) diff --git a/racket/src/io/port/flush-output.rkt b/racket/src/io/port/flush-output.rkt index a5df7c8a1c..76e4f39ffd 100644 --- a/racket/src/io/port/flush-output.rkt +++ b/racket/src/io/port/flush-output.rkt @@ -6,7 +6,8 @@ "port.rkt" "output-port.rkt" "pipe.rkt" - "check.rkt") + "check.rkt" + "fd-port.rkt") (provide flush-output maybe-flush-stdout) @@ -37,5 +38,7 @@ (define (maybe-flush-stdout in) (when (eq? in orig-input-port) - (flush-output orig-output-port) - (flush-output orig-error-port))) + (when (terminal-port? orig-output-port) + (flush-output orig-output-port)) + (when (terminal-port? orig-error-port) + (flush-output orig-error-port))))