
sorawee
2018-12-29 05:10:02
Is there anyway to make merge-input
respect the order? For instance, I have:
;; a.rkt
#lang racket/base
(printf "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n")
(eprintf "BBB\n")
and
;; b.rkt
#lang racket/base
(require racket/match
racket/system
racket/port)
(match-define (list out in _ err proc) (process "racket a.rkt"))
(proc 'wait)
(define new-port (merge-input out err))
(let iter ()
(match (read-line new-port)
[(? string? s) (displayln s)
(iter)]
[else (void)]))
(close-input-port out)
(close-input-port err)
(close-output-port in)
Running a.rkt
directly always yield the right order (AAA...
and then BBB
), but running b.rkt
almost always gives the wrong order. I could switch (merge-input out err)
to (merge-input err out)
to make the order different, but it’s still wrong for a more complicated program.