So, i'm trying to make a nice batch menu but everytime i try to use unicode's fancy lines i just get random characters. Is there any way to put unicode in cmd and or a batch file?
2 Answers
To use unicode, add the code chcp 65001
This will change the code page. It stays that way until you close the window.
If you want to have this always run, (not necessarily recommended, because unicode can sometimes break batches), you can add a reg key string (reg_sz) to HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor and name it AutoRun. Change the value of it to chcp 65001. If you don't want to see the output message from the command, use @chcp 65001>nul instead.
- 3,840
You can create unicode characters from codepoints in the batch file itself.
@echo off
setlocal
chcp 65001 >NUL
call :createUnicodeChar "U+20AC"
call :createUnicodeChar "U+10437"
call :createUnicodeChar "U+10400"
call :createUnicodeChar "U+1F609" smiley
echo %smiley% .. %smiley%
exit /b
:createUnicodeChar
setlocal EnableDelayedExpansion
set "code_point=%~1"
set "code_point=!code_point:U+=!"
set /a code_point=0x!code_point!
if !code_point! LSS 0x10000 (
call :dec2hex_le !code_point! utf16_le_bytes
) ELSE (
set /a "code_point-=0x10000"
set /a "W1_val=((code_point >> 10) & 0x3FF) | 0xD800"
set /a "W2_val=(code_point & 0x3FF) | 0xDC00"
call :dec2hex_le !W1_val! W1_hex
call :dec2hex_le !W2_val! W2_hex
set "utf16_le_bytes=!W1_hex! !W2_hex!"
)
> "!TEMP!\utf16-LE.tmp" (echo ff fe !utf16_le_bytes!)
rem *** Decode file to binary
> nul CertUtil -f -decodehex "!TEMP!\utf16-LE.tmp" "!TEMP!\utf16-LE.tmp"
for /F %%C in ('type "!TEMP!\utf16-LE.tmp"') do if "%~2" == "" (
echo(%%C
) ELSE (
endlocal
set "%~2=%%C"
)
exit /b
:dec2hex_le
set "hex=0123456789ABCDEF"
set val=%1
set "res="
set /a "val|=0x10000"
:dec2hex_le_loop
set /a "nibble=val & 0x0F"
set /a "val>>=4"
set "res=!hex:~%nibble%,1!!res!"
if !val! GTR 1 goto :dec2hex_le_loop
set "%2=!res:~2,4! !res:~0,2!"
exit /b
Output:
€
..
- 433