Re: [racket-users] Converting Windows line-endings for arbitrary ports

2018-08-16 Thread Greg Hendershott
Could you use `read-line`, supplying 'any for the optional `mode` argument?

  
https://docs.racket-lang.org/reference/Byte_and_String_Input.html#(def._((quote._~23~25kernel)._read-line))


If reading in line-sized chunks would be awkward for your existing
code: I suppose you add a second pipe just to do this aspect? :)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Converting Windows line-endings for arbitrary ports

2018-08-16 Thread Philip McGrath
I would like to apply the same line-ending conversion that open-input-file
with a #:mode of 'text does on Windows to arbitrary input ports, like
Racket-level pipes (in the sense of make-pipe).

Specifically, I have an external program that I invoke with system* which
reads from and writes to standard IO. On Windows, I have discovered
(painfully), it writes "\r\n" line endings in its output, but I want to
read "\n" line endings on all platforms. Elsewhere I do this by calling IO
functions with #:mode 'text, but there doesn't seem to be an equivalent
transformation for Racket pipes or ports in general. It looks like the
conversion for open-input-file and friends is implemented in C as part of
rktio
;
it doesn't seem to do be available at the Racket level. I might be able to
use reencode-input-port  with its ability to convert newlines, but it
doesn't seem to be precisely the same transformation as open-input-file.
Likewise, I could probably implement the right transformation myself, but
I'm concerned about introducing subtle bugs, especially because I don't
have ready access to a Windows machine for testing.

Is there an existing solution for this?

Right now, my workaround is to have the external program write to a
temporary file, then read in the temporary file with #:mode 'text.

-Philip

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.