answersLogoWhite

0


Best Answer

Batch files must be saved in ANSI format because that's the only format the CMD shell natively supports. If you save the file in any one of the Unicode formats (UTF8, UTF16, etc) the batch will not execute or will execute up until the first unrecognised symbol, especially if the file also contains a byte-order-mark (BOM).

While the batch file itself must be encoded in ANSI, that does not mean you are limited to just 256 characters. By changing the code page, the same encoding can represent any character you want, you simply need to know in which code page it resides. Whilst editing your batch file, there can only be one code page in effect so any characters you've already entered using a different code page may not display correctly. However, this effect is temporary since changing the code page doesn't change the encoding, it only changes the way that encoding is interpreted by your text editor.

Your batch file will also need to include the CHCP command to change the console code page accordingly as it is executed. However, before you switch code pages, remember to save the current code page so that you can restore it when you're done. This is particularly important if your batch file might be invoked as part of another batch file. If you don't restore the code page, the other batch file may not work as intended. Also, never assume that the current code page is always going to be the system default code page because the default depends on the locale. Always leave things exactly as you found them.

As an example, suppose we wish to display the full range of box drawing characters found in code page 437. Here's how our code will appear in the editor:

@ECHO OFF

REM Save the current code page.

FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%~A) DO SET codepage=%%B

CHCP 437 > NUL

ECHO ÉÍËÍ» ÚÄÂÄ¿ ÖÄÒÄ· ÕÍÑ͸

ECHO º º º ³ ³ ³ º º º ³ ³ ³

ECHO ÌÍÎ͹ ÃÄÅÄ´ ÇÄ×Ķ ÆÍØ͵

ECHO º º º ³ ³ ³ º º º ³ ³ ³

ECHO ÈÍÊͼ ÀÄÁÄÙ ÓÄÐĽ ÔÍÏ;

REM Restore the original code page.

CHCP %codepage% > NUL

Don't worry about all the hieroglyphics, that's simply how Windows-1252 interprets the encodings and is how Windows Notepad will display your batch file. To see the correct symbols you will need to use an editor that supports OEM-US encoding such as Notepad++.

When you execute this batch file, you should see the following output:

╔═╦═╗ ┌─┬─┐ ╓─╥─╖ ╒═╤═╕

║ ║ ║ │ │ │ ║ ║ ║ │ │ │

╠═╬═╣ ├─┼─┤ ╟─╫─╢ ╞═╪═╡

║ ║ ║ │ │ │ ║ ║ ║ │ │ │

╚═╩═╝ └─┴─┘ ╙─╨─╜ ╘═╧═╛

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you enter Unicode or Alt Codes into a Batch File?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you edit your registry from a batch file?

You can only do it with regetit.exe, and plus if you are asking to change it with a batch file ... trying to make a virus?


How do you name a batch program?

Assuming you mean a shell script (AKA batch file), you simply add a .bat as the extension to any plaintext file. There is no limitation for the actual filename aside from this (except for regularly unallowed charachters like > and /). For instance, if you wanted to name your batch file hello world, you would open up a new notepad document, enter your code, then save as File Name: hello world.bat and change the Save as Type: All Files. Windows automatically recognizes any file with the .bat extension as an executable batch file, so to run it, you would just double-click it like any other document or file. To edit the batch file again, you can right click it and select Edit, or use notepad to open it from its respective location. Hope that answers your question.


What are the features of batch file programming?

Batch file programming is dos based programming you have to use dos commands .It is very good to perform some repetitive task in computer programming is easy you should only know the dos commands.


How can you mask your password when typing in a batch file?

Natively, you can't replace characters typed into a batch file from the keyboard with asterisks or any other character to mask what is being typed. You will have to download a special program and run that alongside CMD.exe in order to have this functionality.


How does batch file work?

batch files are used to make long tasks shorter. for example, If I wanted to change the file extension of every file in the folder EXAMPLEFOLDER from .txt to .doc, I could make a batch file that did that instantly, rather than going into the properties of every file and changing the extension manually

Related questions

How do you use Batch File in Microsoft Excel to change the file names of multiple files?

click file, then preferences, next click multiple then enter


How do you enter username and password with a batch file?

You can use the run as command in the batch file if you are using windows xp and i think with wondows 2000, unfortunatly it is open text so you have to use another programme to do that.


What is the extension of batch file?

the extension of a batch file is ".bat"


What are some batch file codes?

Depends on your operating system. Everything you can type into your cmd, powershell or terminal, works in a batch file. Plus you can use conditional and loop statements (syntax depends on your operating system). Under Windows you can turn off output of source on a console by writing "@echo off" as your first line of your batch file or precede every statement by "@."


Can a file with a weird extension but with batch file code be read using another batch file?

Nope, the format of a file is a vital part of a successful batch file. Even if a file with an unknown file format contains working batch file code in it, a batch file will still not be able to read it because of its foreign file extension. If you want the batch file to be able to read the foreign file, then you can set it to rename the mutated file to .bat format and then read it for it to work. Example: @Echo off REN File.Foreign File.bat CALL File.bat exit


What is a batch file?

A batch file is the text file that contains a series of commands that MS-DOS carries out. A batch file is created by COPY CON command after specifying a file name by using extension as .BAT in DOS mode.


How do you extract code from batch file?

You can just open the batch file with notepad and look at the code


Is there any batch file editor to create batch file without learning syntax?

You can't download a program that makes a batch file to do what you want to do. You will need to legally learn about hacking, and then write the file yourself.


A file with a bat file extension is called an what?

A batch file.


What is Batch File Maker?

you can use notepad for creating a batch file. just when you save the file that you made, add .bat as a file extension. like this: "sample.bat".


What do you call a little program made from batch file?

A Batch Script


A group or list of commands?

A Batch. generally in a BATch file.