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

**URL:** <https://racket.discourse.group/t/by-default-read-line-leaves-the-r-character-at-the-end-of-a-line-entered-on-the-command-line-on-windows/2235>\
**Category:** General\
**Created:** [August 21, 2023, 5:12pm UTC](https://racket.discourse.group/t/by-default-read-line-leaves-the-r-character-at-the-end-of-a-line-entered-on-the-command-line-on-windows/2235 "2023-08-21T17:12:37Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![alexh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alexh/32/315_2.png) [@alexh](https://racket.discourse.group/u/alexh)\
**Post date:** [August 21, 2023, 1:24pm UTC](https://racket.discourse.group/t/by-default-read-line-leaves-the-r-character-at-the-end-of-a-line-entered-on-the-command-line-on-windows/2235/2 "2023-08-21T13:24:27Z")

</div>

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":

```scheme
#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:

```c++
#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](https://learn.microsoft.com/en-us/cpp/c-runtime-library/text-and-binary-mode-file-i-o?view=msvc-170)), `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.

---

_[View the full topic](https://racket.discourse.group/t/by-default-read-line-leaves-the-r-character-at-the-end-of-a-line-entered-on-the-command-line-on-windows/2235)._
