Using “En Dash” in an input file to a batch file

前端 未结 2 771
眼角桃花
眼角桃花 2020-12-21 10:31

Most tragically, I got several TFS team projects with an en dash in them.

If you are not familiar with en dash, open up MS Word and type in alt+8211.

You wil

相关标签:
2条回答
  • 2020-12-21 11:11

    I know this is an old post, but I saw no fix here, and it took me some searching before I tried my own fix.

    In Notepad, I changed my font from 'Lucinda Console' to 'TERMINAL', and the dashes (–) changed to The (û) symbol. I just manually used the - on my keyboard using that font, saved my BAT script, and it executed fine.

    0 讨论(0)
  • 2020-12-21 11:23

    The en dash character is Unicode code point U+2013. In Windows code page 1252 it is character number 150. The û charcter is character number 150 in code page 437. So it looks like one process is writing a file in code page 1252, while another is reading it using code page 437.

    Ideally, all code pages other than Unicode should be thrown out along with World Wars, small pox, and other relics of the 20th century. Unfortunately, the Windows console makes this rather difficult.

    Since code page 437 is the default console code page for most Windows installations, I suspect that it is this default setting that is causing these problems. (File names are stored by the OS in Unicode, so that part, at least, is correct.) Since code page 437 does not include the en dash character, any system using that code page will have to resort to a fallback mechanism to render the file names, such as a question mark.

    By changing the console code page to something that does support the en dash character, such as 1252, this problem may be corrected.

    You can change this code page with the following command.

    chcp 1252
    

    This command should probably be placed at the beginning of your batch file.

    This is a terrible hack that will be necessary until you can convert your system to something modern that supports Unicode from top to bottom.

    You may also want to try it in Powershell, since PS does support Unicode.

    0 讨论(0)
提交回复
热议问题