[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Q] HOWTO redirect a i/o-port in Unix??



Quoting Matthew Flatt:
> The problem is that `read-string!' waits until it can fill the string
> or until EOF, but your application relies on line-based
> question--response I/O.

A further correction. On closer inspection, I see your example doesn't
even have a newline in the stream.

Usually, /bin/cat doesn't flush its output until it sees a newline:

 > (define p (process "cat"))
 > (display "hello" (cadr p))
 > (read-char (car p))
 [stuck]

In contrast:

 > (define p (process "cat"))
 > (display "hello" (cadr p))
 > (newline (cadr p))
 > (read-char (car p))
 #\h

If /bin/cat flushed chars on some other boundary than lines, you'd need
the new, not-yet-existent primitive in MzScheme to make things work
right (or you'd have to busy-wait with `char-ready?'). In practice,
I've found that either `read-string!' or `read-line' has worked for all
my real programs.

Matthew