Batch file encoding

Viewed 102194

I would like to deal with filename containing strange characters, like the French é.

Everything is working fine in the shell:

C:\somedir\>ren -hélice hélice

I know if I put this line in a .bat file, I obtain the following result:

C:\somedir\>ren -hÚlice hÚlice

See ? é have been replaced by Ú.

The same is true for command output. If I dir some directory in the shell, the output is fine. If I redirect this output to a file, some characters are transformed.

So how can I tell cmd.exe how to interpret what appears as an é in my batch file, is really an é and not a Ú or a comma?

So there is no way when executing a .bat file to give an hint about the codepage in which it was written?

6 Answers

I had polish signs inside the code in R (eg. ą, ę, ź, ż etc.) and had the problem while running this R script with .bat file (in the output file .Rout instead of those signs there were signs like %, &, # etc. and the code didn't run to the end).

My solution:

  1. Save R script with encoding: File > Save with encoding > CP1250
  2. Run .bat file

It worked for me but if there is still the problem, try to use the other encodings.

In Visual Studio Code, click on the encoding at the bottom, choose Save with encoding, then DOS(CP437).

Related