batch-fileextended-ascii

Is it possible to use extened ASCII characters in a BAT file?


I have a bunch of dynamically created *.BAT files. These BAT files are used to create folders in a server. Just one line in each BAT file, such as: MKDIR \NetworkShare\abc\123

This "abc\123" string is from a database.

It runs OK for a while to create thousands subfolders on demand until today it stopped creating a special subfolder which has a "close single quote" (Alt + 0146 if typing from dos prompt) in the string.

I did some research and found that this "close single quote" is an extended ASCII character. It can't be saved properly in ANSI BAT file (end up as something else). I tried UNICODE and UTF-8 BAT file, but it doesn't work.

The only near-close solution is that I tried a binary editor to make sure it's code 146, but code 146 gives me Æ (ALT-146) not "close single quote" (Alt + 0146).

I know I can manually type special characters in DOS prompt (by using keyboard Alt + ). But is there a way to properly save this "close single quote" (Alt + 0146) in BAT file so I can execute them dynamically?

The host system is Windows Server 2003 US-English.


Solution

  • Thank you for this CHCP 65001 trick. It leads to proper solution:

    I took follow steps to resolve the issue:

    +++++++++++++++++++

    Prepare the BAT Text File (either manually or dynamically)

    +++++++++++++++++++

    (1) Make the first line blank (this is necessary, because there are hidden chars in the first line for UTF-8 text file)

    (2) Put CHCP 65001 as second line

    (3) main line here: MKDIR \networkshare\abc(right single quote-->this is special extended ASCII char)\123

    (4) make sure the BAT file saved as UTF-8

    +++++++++++++++++++

    Now it's the CMD.EXE trick

    +++++++++++++++++++

    (1) Start cmd.exe

    (2) open cmd.exe black screen property

    (3) make sure the black screen font is "true type" i.e. "TT" like. By default, it is raster font, can not handle special ascii code properly. (This is the key step)

    (4) now I can run my BAT to handle those extended ASCII chars properly.