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

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



On Mar 12, Matthew Flatt wrote:
> I should have been more careful in my original post.
> 
> The bottom line is that you want to use `read-line' instead of
> `read-string!':
> 
> ...
> 
> 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.

But wouldn't it fill whatever possible in case there's an EOF waiting?
I did close the output port into the 1st process, which, as far as I
understood, should have caused it to die, closing its output port
which propagates to the second thread as well...


> Previously in this thread (I think), I mentioned that MzScheme needs
> a primitive like `read-string', except that it returns immediately
> if there's something to read, and blocks only if nothing's
> available. With that, we could have a truly general and reasonably
> efficient `copy-stream'. The next verison of MzScheme will likely
> have such a primitive.

I don't get it - isn't that what read-string is supposed to do now?
"Otherwise, if fewer than k characters are available before an
end-of-file is encountered, then the returned string will contain only
those characters before the end-of-file (i.e., the returned string's
length will be less than k). If no characters are available before an
end-of-file, then eof is returned."  Or are you talking about general
availability of characters, unrelated to the EOF?


> Without it, we need at least `copy-stream', as before, and
> `copy-stream/lines', as above.

Anyway, I hope I can work through this...  This whole process/ports
thing is pretty messy...


On Mar 12, Matthew Flatt wrote:
> 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:

Yeah, I'm aware of that - but I did have newlines...  The cat thing
was actually an attempt to clarify things, but I think that my real
example would be more complicted - I want to do somwthing similar to
what pack does (gzip into mmencode) in a more robust way of starting
two processes and using copy-stream to connect them.  Maybe I'll just
stick to that (process "gzip -c | mmencode > ..." dest), I just hope
it doesn't depend on things like shell etc...

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
         http://www.cs.cornell.edu/eli/meaning.html        Maze is Life!