2

I'm working in Windows and appending lines to a text file in Red using

write/append/lines %MC_testfile.txt "output text here"

And the output text is duly appended but not on a new line. How do I get my appended text on a new line?

  • 2
    On Windows, if I say: `loop 5 [write/append/lines %testfile.txt "line"]` and then `print read %testfile.txt`, there are linebreaks. There are also linebreaks if it's loaded into Notepad.exe. Can you give a [Minimal, Complete, Verifiable Example](http://stackoverflow.com/help/mcve)? – HostileFork says dont trust SE Feb 15 '17 at 20:01
  • Hi HF - thanks for all your Red stuff, it's been very helpful! I copied and pasted your code and got no line breaks on the console and none in notepad! I stuck your code in a file and ran it - still no line breaks. I'm on windows 10 - Red 0.6.1 - it's a mystery! – ally bally bee Feb 15 '17 at 23:28
  • HF - Thanks for the pointer to the fix. I'll have a look at getting the fixed version. I'm afraid the block solution raises another question! I can't write blocks to files - I get this error - Script Error: write does not allow block! for its data argument – ally bally bee Feb 16 '17 at 09:23
  • @HostileFork - thanks for the help - as you can tell I'm very new to this. I'll get a newer build and retry. Thanks again for taking the time. – ally bally bee Feb 16 '17 at 10:46

2 Answers2

3

You appear to be encountering a bug that was fixed very recently (apparently more recently than the build you are using):

Issue #2430: write/lines only writes end-of-lines if argument is block

FIX: issue #2430

Two resources to help with this kind of thing in the future:

Given Red's early state, it's good to do a keyword search in the issues database before posting to StackOverflow. You should search on all issues (the search defaults to open, but you can remove that clause to get closed ones too). It would have found this one:

GitHub Query Filter is:issue write/lines

You also might find a related issue that helps inform whatever you're seeing.

The other thing to know about is the automated builds of the master branch from the download page:

http://www.red-lang.org/p/download.html

If reporting a problem to a project, it always helps to try it in both the stable and the latest, to see if it's a regression or possibly fixed.

0

There is another way:

write/append %file.txt form reduce [newline now "some text"]

result:

29-Jun-2020/17:33:22+03:00 some text
Dmitry Bubnenkov
  • 9,415
  • 19
  • 85
  • 145