2

I am trying to output text with *nix line endings from a windows dart vm, and it seems to be always replacing the \n with \r\n:

#!/usr/bin/env dart

# foo.dart

import 'dart:io';

main() {
  stdout.write('a\nb\nc\n');
  stdout.write('a\x0Ab\x0Ac\x0A');
}

Here's what I get when running from cygwin

$ foo.dart | foo.txt
$ cat -A foo.txt
a^M$
b^M$
c^M$
a^M$
b^M$
c^M$

Is there a way to output text without automatic carriage returns insertion?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Sean Eagan
  • 1,130
  • 7
  • 9

1 Answers1

4

Problem is that stdout is by default opened in text mode, in which Windows itself automatically converts LF to CRLF.

If it were C/C++ generally speaking you will be able to switch stdout to binary mode using _setmode(see how C output LF to stdout without being changed to CR LF?).

In Dart you don't have access to that API function.

I would raise a request for that on dartbug.com/new.

Community
  • 1
  • 1
aam
  • 56
  • 1