windows - Why do special characters in a batch file print as a question mark? -


so working on batch file game while ago, , reason prints question mark symbol instead of smiley face symbol (which when press ctrl+a in command prompt).

my program screenshot

i have same problem these others symbols:

ctrl+a smiley face ctrl+b dark smiley face ctrl+d diamond ctrl+e clover ctrl+f ace ctrl+n music symbol crtl+o random circlish symbol ctrl+p left arrow ctrl+q right arrow ctrl+r , down arrows ctrl+t line wrap symbol ctrl+u double s ctrl+v thick underscore ctrl+w , down arrow line @ bottom ctrl+x arrow ctrl+y down arrow 

source instructables article: how use special characters in cmd

i tried cmd screenshot

i running windows 10 pro latest update. have tried find solution fix problem had no success. appreciated.

the behavior of oem alt codes misleading codes 1-31 , 127. system's oem codepage superset of ascii. however, range of alt codes doesn't input ascii control characters, rather characters old ibm pc systems display , print ascii control characters. example, alt+1 enters "☺" (u+263a, white smiling face) instead of ascii soh (u+0001, start of heading). compound this, default behavior of widechartomultibyte when encoding such characters oem codepage use corresponding ascii control character best-fit encoding. text editor may not warn see not you'll get.

the console doesn't display control characters old ibm pc graphics characters. interprets of them such u+0009 (horizontal tab -- advance cursor 8 spaces) , u+000d (carriage return -- advance cursor beginning of next line), of them displayed current font's glyph unmapped character, such boxed question mark or empty box. if want print "☺" console, should use console's wide-character api, works windows native unicode (utf-16le) strings.

fortunately cmd unicode application, there's no problem printing "☺" console. problem encoding use batch script. general solution save batch file utf-8 without bom (byte order mark). you'll need ide or text editor can save utf-8 without bom, such notepad++.

cmd decodes batch script line line using legacy console codepage, can change utf-8 command chcp.com 65001. advise against changing utf-8 permanently because, depending on windows version, console has various bugs codepage 65001. can switch utf-8 temporarily load non-ascii strings environment variables. otherwise keep rest of batch file strictly 7-bit ascii avoid localization problems.

here's example. there more generalized way go creating of these local environment variables, it's show works in principle.

graphics_ctl.bat

@echo off rem ascii control-character graphics rem file encoding: utf-8 (no bom)  rem set console codepage 65001 (utf-8). /f "tokens=2 delims=:" %%a in ('chcp.com') set "console_codepage=%%a" set "console_codepage=%console_codepage: =%" chcp.com 65001 >nul  set "gctl_white_smiling_face=☺" set "gctl_black_smiling_face=☻" set "gctl_black_heart_suit=♥" set "gctl_black_diamond_suit=♦" set "gctl_black_club_suit=♣" set "gctl_black_spade_suit=♠" set "gctl_bullet=•" set "gctl_inverse_bullet=◘" set "gctl_white_circle=○" set "gctl_inverse_white_circle=◙" set "gctl_male_sign=♂" set "gctl_female_sign=♀" set "gctl_eighth_note=♪" set "gctl_beamed_eighth_notes=♫" set "gctl_white_sun_with_rays=☼" set "gctl_black_right_pointer=►" set "gctl_black_left_pointer=◄" set "gctl_up_down_arrow=↕" set "gctl_double_exclamation_mark=‼" set "gctl_pilcrow_sign=¶" set "gctl_section_sign=§" set "gctl_black_rectangle=▬" set "gctl_up_down_arrow_with_base=↨" set "gctl_up_arrow=↑" set "gctl_down_arrow=↓" set "gctl_right_arrow=→" set "gctl_left_arrow=←" set "gctl_right_angle=∟" set "gctl_left_right_arrow=↔" set "gctl_black_up_triangle=▲" set "gctl_black_down_triangle=▼" set "gctl_house=⌂"  rem restore previous console codepage. chcp.com %console_codepage% >nul 

graphics_box.bat

@echo off rem box-drawing graphics rem file encoding: utf-8 (no bom)  rem set console codepage 65001 (utf-8). /f "tokens=2 delims=:" %%a in ('chcp.com') set "console_codepage=%%a" set "console_codepage=%console_codepage: =%" chcp.com 65001 >nul  set "gbox_light_shade=░" set "gbox_medium_shade=▒" set "gbox_dark_shade=▓" set "gbox_light_vertical=│" set "gbox_light_vertical_and_left=┤" set "gbox_vertical_single_and_left_double=╡" set "gbox_vertical_double_and_left_single=╢" set "gbox_down_double_and_left_single=╖" set "gbox_down_single_and_left_double=╕" set "gbox_double_vertical_and_left=╣" set "gbox_double_vertical=║" set "gbox_double_down_and_left=╗" set "gbox_double_up_and_left=╝" set "gbox_up_double_and_left_single=╜" set "gbox_up_single_and_left_double=╛" set "gbox_light_down_and_left=┐" set "gbox_light_up_and_right=└" set "gbox_light_up_and_horizontal=┴" set "gbox_light_down_and_horizontal=┬" set "gbox_light_vertical_and_right=├" set "gbox_light_horizontal=─" set "gbox_light_vertical_and_horizontal=┼" set "gbox_vertical_single_and_right_double=╞" set "gbox_vertical_double_and_right_single=╟" set "gbox_double_up_and_right=╚" set "gbox_double_down_and_right=╔" set "gbox_double_up_and_horizontal=╩" set "gbox_double_down_and_horizontal=╦" set "gbox_double_vertical_and_right=╠" set "gbox_double_horizontal=═" set "gbox_double_vertical_and_horizontal=╬" set "gbox_up_single_and_horizontal_double=╧" set "gbox_up_double_and_horizontal_single=╨" set "gbox_down_single_and_horizontal_double=╤" set "gbox_down_double_and_horizontal_single=╥" set "gbox_up_double_and_right_single=╙" set "gbox_up_single_and_right_double=╘" set "gbox_down_single_and_right_double=╒" set "gbox_down_double_and_right_single=╓" set "gbox_vertical_double_and_horizontal_single=╫" set "gbox_vertical_single_and_horizontal_double=╪" set "gbox_light_up_and_left=┘" set "gbox_light_down_and_right=┌" set "gbox_full_block=█" set "gbox_lower_half_block=▄" set "gbox_left_half_block=▌" set "gbox_right_half_block=▐" set "gbox_upper_half_block=▀"  rem restore previous console codepage. chcp.com %console_codepage% >nul 

graphics_test.bat

@echo off setlocal  set "scriptdir=%~dp0" call "%scriptdir%\graphics_ctl.bat" call "%scriptdir%\graphics_box.bat"  echo. echo ascii control-character graphics echo ---------------------------------------------- echo gctl_white_smiling_face      = %gctl_white_smiling_face% echo gctl_black_smiling_face      = %gctl_black_smiling_face% echo gctl_black_heart_suit        = %gctl_black_heart_suit% echo gctl_black_diamond_suit      = %gctl_black_diamond_suit% echo gctl_black_club_suit         = %gctl_black_club_suit% echo gctl_black_spade_suit        = %gctl_black_spade_suit% echo gctl_bullet                  = %gctl_bullet% echo gctl_inverse_bullet          = %gctl_inverse_bullet% echo gctl_white_circle            = %gctl_white_circle% echo gctl_inverse_white_circle    = %gctl_inverse_white_circle% echo gctl_male_sign               = %gctl_male_sign% echo gctl_female_sign             = %gctl_female_sign% echo gctl_eighth_note             = %gctl_eighth_note% echo gctl_beamed_eighth_notes     = %gctl_beamed_eighth_notes% echo gctl_white_sun_with_rays     = %gctl_white_sun_with_rays% echo gctl_black_right_pointer     = %gctl_black_right_pointer% echo gctl_black_left_pointer      = %gctl_black_left_pointer% echo gctl_up_down_arrow           = %gctl_up_down_arrow% echo gctl_double_exclamation_mark = %gctl_double_exclamation_mark% echo gctl_pilcrow_sign            = %gctl_pilcrow_sign% echo gctl_section_sign            = %gctl_section_sign% echo gctl_black_rectangle         = %gctl_black_rectangle% echo gctl_up_down_arrow_with_base = %gctl_up_down_arrow_with_base% echo gctl_up_arrow                = %gctl_up_arrow% echo gctl_down_arrow              = %gctl_down_arrow% echo gctl_right_arrow             = %gctl_right_arrow% echo gctl_left_arrow              = %gctl_left_arrow% echo gctl_right_angle             = %gctl_right_angle% echo gctl_left_right_arrow        = %gctl_left_right_arrow% echo gctl_black_up_triangle       = %gctl_black_up_triangle% echo gctl_black_down_triangle     = %gctl_black_down_triangle% echo gctl_house                   = %gctl_house%  echo. echo box-drawing graphics echo ---------------------------------------------- echo gbox_light_shade                           = %gbox_light_shade% echo gbox_medium_shade                          = %gbox_medium_shade% echo gbox_dark_shade                            = %gbox_dark_shade% echo gbox_light_vertical                        = %gbox_light_vertical% echo gbox_light_vertical_and_left               = %gbox_light_vertical_and_left% echo gbox_vertical_single_and_left_double       = %gbox_vertical_single_and_left_double% echo gbox_vertical_double_and_left_single       = %gbox_vertical_double_and_left_single% echo gbox_down_double_and_left_single           = %gbox_down_double_and_left_single% echo gbox_down_single_and_left_double           = %gbox_down_single_and_left_double% echo gbox_double_vertical_and_left              = %gbox_double_vertical_and_left% echo gbox_double_vertical                       = %gbox_double_vertical% echo gbox_double_down_and_left                  = %gbox_double_down_and_left% echo gbox_double_up_and_left                    = %gbox_double_up_and_left% echo gbox_up_double_and_left_single             = %gbox_up_double_and_left_single% echo gbox_up_single_and_left_double             = %gbox_up_single_and_left_double% echo gbox_light_down_and_left                   = %gbox_light_down_and_left% echo gbox_light_up_and_right                    = %gbox_light_up_and_right% echo gbox_light_up_and_horizontal               = %gbox_light_up_and_horizontal% echo gbox_light_down_and_horizontal             = %gbox_light_down_and_horizontal% echo gbox_light_vertical_and_right              = %gbox_light_vertical_and_right% echo gbox_light_horizontal                      = %gbox_light_horizontal% echo gbox_light_vertical_and_horizontal         = %gbox_light_vertical_and_horizontal% echo gbox_vertical_single_and_right_double      = %gbox_vertical_single_and_right_double% echo gbox_vertical_double_and_right_single      = %gbox_vertical_double_and_right_single% echo gbox_double_up_and_right                   = %gbox_double_up_and_right% echo gbox_double_down_and_right                 = %gbox_double_down_and_right% echo gbox_double_up_and_horizontal              = %gbox_double_up_and_horizontal% echo gbox_double_down_and_horizontal            = %gbox_double_down_and_horizontal% echo gbox_double_vertical_and_right             = %gbox_double_vertical_and_right% echo gbox_double_horizontal                     = %gbox_double_horizontal% echo gbox_double_vertical_and_horizontal        = %gbox_double_vertical_and_horizontal% echo gbox_up_single_and_horizontal_double       = %gbox_up_single_and_horizontal_double% echo gbox_up_double_and_horizontal_single       = %gbox_up_double_and_horizontal_single% echo gbox_down_single_and_horizontal_double     = %gbox_down_single_and_horizontal_double% echo gbox_down_double_and_horizontal_single     = %gbox_down_double_and_horizontal_single% echo gbox_up_double_and_right_single            = %gbox_up_double_and_right_single% echo gbox_up_single_and_right_double            = %gbox_up_single_and_right_double% echo gbox_down_single_and_right_double          = %gbox_down_single_and_right_double% echo gbox_down_double_and_right_single          = %gbox_down_double_and_right_single% echo gbox_vertical_double_and_horizontal_single = %gbox_vertical_double_and_horizontal_single% echo gbox_vertical_single_and_horizontal_double = %gbox_vertical_single_and_horizontal_double% echo gbox_light_up_and_left                     = %gbox_light_up_and_left% echo gbox_light_down_and_right                  = %gbox_light_down_and_right% echo gbox_full_block                            = %gbox_full_block% echo gbox_lower_half_block                      = %gbox_lower_half_block% echo gbox_left_half_block                       = %gbox_left_half_block% echo gbox_right_half_block                      = %gbox_right_half_block% echo gbox_upper_half_block                      = %gbox_upper_half_block% 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -