By default read-line leaves the \r character at the end of a line entered on the command line on Windows

I think the default for read-line is fine, and it is consistent with other languages.

I think the problem is that, in the Racket executable, stdin and stdout are opened in binary instead of text mode -- on Linux, this does not matter, but on Windows this causes the port to not translate the "\r\n" sequence into "\n".

A similar problem exists when writing. For example, on Window, when running the following program and redirecting the output to a file, produces a single "\n" in the file instead of the expected "\r\n":

#lang racket
(write-string "Hello World\n")

The equivalent C++ program, when its output is redirected to a file, produces the expected "\r\n" at the end of the greeting:

#include <iostream>

int main()
{
    std::cout << "Hello World!\n";
    return 0;
}

The problem with the output line endings is less noticeable, since most windows utilities (including the famous notepad.exe) now handle files with "\n".

According to (Text and Binary Mode File I/O | Microsoft Learn), stdin, stdout and stderr are always opened in text mode by default, and the user needs to re-open them in binary mode if they want binary output (I don't think there is a Racket facility to change the text/binary mode of an open port)

Alex.