Az-
Az-

Reputation: 55

unicode not displaying from bat

my unicode characters aren't displaying correctly from a run batch file but they display fine in the cmd prompt

(note: you have to have set cmd to use consolas for this to work)

so i have a text file that contains

╔══════╗
║      ║
╚══════╝

and a bat file that contains

chcp 65001
@echo off 
cls
type textfile.txt
pause

when i open a cmd window and type in chcp 65001 then type textfile.txt i get

╔══════╗
║      ║
╚══════╝

but if i try to run the bat file all i get is

´╗┐ÔòöÔòÉÔòÉÔòÉÔòÉÔòÉÔòÉÔòù
Ôòæ      Ôòæ
ÔòÜÔòÉÔòÉÔòÉÔòÉÔòÉÔòÉÔòØ

which is what normally happens if i dont use chcp.. for some reason when run from a bat file the type command isn't using the type page?

Upvotes: 1

Views: 826

Answers (1)

woxxom
woxxom

Reputation: 73566

It happens because your batch file is saved in UTF8 encoding with a standard 3-byte BOM (Byte Order Mark) at the beginning. These characters aren't recognized by CMD interpreter, it sees them as a part of the first line and naturally can't execute ???chcp.

  • Resave your file in UTF-8 without BOM
  • Or add an empty line at the beginning

Upvotes: 2

Related Questions