Problem: My Django app is introducing a CR before each CRLF when writing to a file a string which has been read in via render_to_string. In my template files, I used CRLFs, and the Django processing app writes a file which adds a CR before each CRLF. See below for code details.
However: this only happens with my app which is on my clients' Windows Server 12R2 VM which is located in France. My physical Windows 10 laptop, my ubuntu instances, and my AWS Windows Server 12 instance (which I use for testing before installing on my client's machine) do not add the CRs.
Caveat: For security reasons, I can only access my client's VM via remote desktop, so I need to set an appointment with the IT group in order to explore and debug the problem. And, that is a 9 hour time difference and takes his valuable time. Thus, I need to re-create this problem on my AWS instance so that I can try to debug my code. And, when I say it introduces a CR instead of CRLF, then I might be remembering it wrong -- it could be that my code introduces a LF instead of a CRLF. I have been using Notepad++ and "showing all characters" in order to see the CR (or LF) and CRLF in the generated files. I think that Notepad++ said my faulty file is "Macintosh" while my starting template file is "Dos\Windows."
So what: Well, the generated file is an R script. And, windows R dislikes CR as newlines by giving an error after reading the first line. If I take the generated R script and open it in Notepad++ and then change the newlines (via the lower right hand of the status bar) to Dos\Windows, then my Rscript will work fine.
A few more details: Here is some of the code so you can see exactly how I am reading/rendering the template and how I am saving it to a file. There are no non-ASCII chars in my template nor in the template dict, so I don't suspect it is a unicode issue (I am using python 2):
rstring = render_to_string('helpers.R') + "\n" + render_to_string('Rcalc-template.R', {'debug':1})
rscript_file = os.path.join(tmpdir, 'Rcalc-rendered.R')
fh = open(rscript_file, mode="w")
with fh:
fh.write(rstring)
subprocess.call(['Rscript', rscript_file],
universal_newlines=True,
stdout=log_filename,
stderr=subprocess.STDOUT,
shell=False)
What I need from you: if anyone has an idea about how I can get my AWS Windows 2012R2 instance to behave like the Windows 2012R2 VM in France, then that would be super helpful. I tried changing the language of my AWS instance to French, but that didn't do it, i.e. my app generated files with CRLFs only. I'm not really sure where to go from here. Thanks in advance!