-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os: output CR LF for \n on Windows #28822
Comments
People seem to have managed so far without this change on Windows. Changing this now would almost certainly break people. |
Can this be changed for Go 2.0? The longer you wait to make this change, the worse it will be. |
It's been nine years. I don't think the world is going to end. |
And what will "\r\n" do? |
It will be useful when redirecting a command line program's output to a file. For example:
The See also: https://en.wikipedia.org/wiki/Newline#Representation |
The problem is that sometimes people really do want just |
This is my indivisually opinion. I have ported many UNIX applications to Windows so far. In many cases, the tests are failed due to the difference in the line feed code, people had frustrations after ported to Windows too. After I met Go where the line feed code is "\n", I feel this problem seems to became fewer, and I noticed the portability of Go is very nice. Using Go, we were able to port UNIX applications to Windows with just small changes. Recently, Notepad on Windows10 support to open a file that have UNIX line code. I feel that the time will come for Windows to abandon "\r\n" in same as the Mac abandoned "\r". https://blogs.msdn.microsoft.com/commandline/2018/05/08/extended-eol-in-notepad/ I use bufio.Scanner when reading the output of a command that not known the line feed code. |
@jftuga I am not asking you what Side note: Windows programs write Notepad, as mentioned above, was one application that did not work. However, wordpad (write.exe) does. Native command line utilities work too. |
Ideally, But I am really not sure about this. Originally, I was only thinking about |
https://nurmi-labs.blogspot.com/2016/11/git.html Git-2.10.0-32-bit.exe includes dos2unix.exe and unix2dos.exe http://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/msys-1.0.11/ MSYS-1.0.11.exe contains the awk scripts d2u and u2d https://nurmi-labs.blogspot.com/2015/10/awk.html link to UNIX awk https://nurmi-labs.blogspot.com/2017/05/9pvfs.html links to pre-compiled watcom-1.9 and -2.0 awk.exe versions whether the d2u or u2d (above) scripts work using the UNIX and/or the watcom-1.9 and -2.0 awk.exe versions I am uninformed on |
Can we simply consider the case of |
I am used to dealing with BOM, CRLF, executable scripts, and file permissions, after having used different Windows subsystems, win32, Interix, and WSL, |
@jftuga Your suggestion is unfortunately not as simple as it sounds. If we adopted #13473 (for Go 2) then it would be at least feasible to wrap the default values of |
From Emacs' GUI frontend one can change the end-of-line style on an open file via the second button from the left on the modeline. Vim is now 27 years old (according to Bram Moolenaar). Help poor children in Uganda! I presume the GUI frontend, gvim.exe, likewise as the Linux version, includes in the menu's Edit dropdown, an entry for File Settings, wherein one navigates to File Format, which opens a popup from where one can 'Select format for writing the file', i.e., Unix, Dos, and Mac, respectively LF, CRLF, and CR. https://nurmi-labs.blogspot.com/2015/10/regexp.html 9pm051031.zip BOMs if present will show up on the first line of flat files running 'cat filename' using 9term.exe, and can be edited out using sam.exe, using the backspace key. See also: https://github.com/nurmi-labs/9pm |
I like this idea for Go 2. What is the best way to determine if this is a good long-term idea or not? |
What programs (other than notepad and the batch interpreter) have trouble with pure line feeds on the consumer side? I feel like this is a step back for Go on Windows. It would break many Go ports of unix tools that have deterministic output across operating systems. |
To be honest, I think it's unlikely that we would make this change in Go 2. The argument in favor would have to demonstrate workflows that do not work today but would start working if we made the change. It's not enough to show that Go programs do not work like Windows programs; we need to know what is actually broken by that fact. |
Here's an argument against modifying the behavior of |
https://github.com/golang/protobuf Would the above be relevant in regards to the previous comment? |
|
I vote to close this ticket. There are too many unknowns. For example.
If I compile a program on windows and runs on windows should it produce windows line endings for all io.Writers or only just os.Stdout?
What about if I compile a program from Linux to goos=windows, what rules apply then?
What if I compile a program on Linux and pipe it’s output to a file then move that file to a windows machine?
There are just too many edge cases to make a blanket rule like “println uses \r\n on windows” practical. Additionally the fact that we’ve survived nine years without needing to make this change suggests that this is not a place to spend the limited Go 2.0 innovation tokens.
… On 17 Nov 2018, at 13:06, as ***@***.***> wrote:
encoding/gob moreso
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
If anyone cares, I support @ianlancetaylor
and @mvdan argument
We need to see the problem with what happens now, before we consider changing it. We should not just follow what https://en.wikipedia.org/wiki/Newline#Representation says. I also looked to see what gcc does to printf("a\n"); (it outputs "a\r\n") and to printf("a\r\n"); (it outputs "a\r\r\n"). Still that does not sway me towards doing the same in Go. Alex |
Another argument against changing the code might be maintaining consistency across Windows environment subsystems, win32/win64 and WSL. While the cygnus port (a posix layer above win32/win64) isn't a supported platform for golang, cygwin occasionally shows up in golang issues and/or threads, however I would point out that, IIRC, I.L.T. wrote in summer of 2012 that "...cygwin binaries are considerably slower than Windows binaries". Google Code Archive I'd also like to see this issue closed. |
From my experience working with systems with different line endings, any solution that tries to be clever and produce different line endings depending on some logic, creates more problems that it solves. Every one of them has different logic, every piece of code that accepts line endings have different logic. In the end you almost always end up with some glue code that ties incompatible systems together. I vote we leave Go as is. Being opinionated is good in cases like that. At least we have consistent ecosystem that works the same everywhere. If some ancient piece of code breaks because of that, it's better to fix it or write some glue code. More reasons to write your programs properly from the beginning. |
As a long time Go, Windows, and Linux user, I would view this as disastrous. I do not like programs that try to be smart about line endings. This is especially disastrous when you try to have some type of reproducible output. This type of logic inevitably must try to distinguish between "text" and "binary" modes. I remember old FTP programs where if you downloaded a program or image in text mode it would corrupt it due to this feature. I believe this issue should be closed as won't fix. |
You may want to review how Java has handled this from its inception. Just define a platform constant LineSeperator then you can create TextReader/Writer types that perform bidirectional encoding as needed. They developer can wrap the standard os.Stdout as needed. Seems the only easy way to not break backward compatibility. |
Consider exploring on a Wiki page using PowerShell to output alternate end-of-line style plus BOM and minus BOM, for the win32/win64 environment subsystem, if that really isn't satisfactory, then revisit the current issue. |
OP here. I just want to thank everyone for considering this change. I know it would/could be a big change. Would it be possible to make this a user-defined setting within the fmt package? The setting could be enabled by a function that changes the output of
|
the following comment addressed a question, which has remained unanswered |
@forskning: I will work on a list of programs and let you know my results tomorrow. |
I prefer to add implementation of Writer to write CR LF when write LF instead of add fmt.useNativeNewline. |
I've sent an enquiry to someone from the 'PowerShell Team' (a GitHub organization) if they would be inclined chip in. |
We are definitely not going to add a setting to the fmt package. Sorry. |
I created a text file that contained just LF and compared it to a file that had CRLF endings. I opened the LF file. MS Word 2016 & Excel read the file OK, but when it saved the file, both programs converted LF to CRLF. I don't see a problem with this - just an observation. VS Code, Notepad++, Sublime Text, Visual Studio 2017 had no problems opening/saving files (as expected). My version of the Windows 10 Notepad did not work properly, but as previously mentioned the very latest version of the Windows 10 fixes this. Batch files, using cmd.exe, definitely have a problem with just LF endings. I would see this error when reading the the LF file, but not the CRLF file: I did some limited testing with PowerShell and it seemed OK with just LF, but I don't know enough about PS to make a definitive statement one way or the other. I only tested In summary, as long as you are not using |
What about mintty.exe? |
runemacs.exe M-x eshell outputs CRLF % cat eshell_out | od -tx1 |
I want to know about the original problem. Why output of LF is not good for you? And how many cases that is higher priority that should be CRLF than LF? IMHO, in many cases, CRLF that is needed is fewer than LF. At least for Go language, fmt.Println must work as same on all environments since it should be cross compiled with same code. If CRLF is needed, the programmer should use CRLF intentionally, I think. |
Looks like the solution is to learn Elisp or PowerShell coding. I wouldn't mind if this issue stayed open a few weeks to see if any PowerShell users added comments. |
If anyone cares, the bug in the 'file' command has been fixed. file/file@6d90cbf |
This more concisely describes potential issues than what I previously posted: https://en.wikipedia.org/wiki/Newline#Issues_with_different_newline_formats |
here's Haskell's implementation http://hackage.haskell.org/package/base-4.12.0.0/docs/System-IO.html |
Consensus seems against this proposal. A couple of other coding languages' approaches to the subject have been cited in this issue. DOS-style CRLF can be output using existing software provided in Windows 10, so I'm going to suggest closing. |
We aren't going to do this, so closing. |
OP here, thanks for everyone's consideration on this. I really appreciate it. |
any one, how to send binary to client with ResponseWriter in windows platform? 0a turns to 0d 0a!! |
em, the httpie python client converting it. no problem with golang ResponseWriter. |
This issue is closed. For questions and help, see https://golang.org/wiki/Questions. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: