I wish to use the ♪ character inside a custom prompt for command prompt. This needs to be done from within my AutoRun batch file. chcp gives output Active code page: 437. If I type into the console via cmd.exe running on the Windows Terminal app prompt ♪$G, it works as expected, changing the prompt to ♪>.
However, if I type prompt ♪$G into a .bat file with vscode with encoding CP 437 or Windows 1252, the output is now:
prompt ?$G
?>
When saved with encoding UTF-8, the output is:
prompt ΓÖ¬$G
ΓÖ¬>
How can I change the prompt to ♪> from within a batch file? What encoding should the file be saved in? Will I need to use a hex editor in any way?
To use the ♪ character in a batch file, you need to save the file using the UTF-8 encoding.
You can do this in most text editors, including VS Code.
When you run the batch file, you may need to change the console code page to UTF-8 to ensure that the character is displayed correctly.
You can do this by adding the following line to your batch file:
This will change the console code page to UTF-8. After that, you can set the prompt using the ♪ character as follows:
This should set the prompt to ♪>.
You should not need to use a hex editor.
For example you can test with batch file below :
This batch file sets up the command prompt with a custom prompt character and then launches a new instance of the command prompt with the
/Kswitch, which keeps the new command prompt window open after executing any commands.Here's a breakdown of the commands:
@echooff turns off the display of each command in the command prompt, so they are not displayed as they are executed.clsclears the command prompt screen.Chcp 65001sets the console code page to UTF-8, so that it can display special characters like the music note symbol (♪).prompt ♪$Gsets the command prompt to display a music note symbol (♪) followed by a greater-than symbol (>) as the command prompt.CMD /Klaunches a new instance of the command prompt and keeps it open.@echo onturns on the display of each command in the new command prompt window.Edit :
Changing the console code page to
UTF-8 (65001)can cause issues when piping text between applications that use the C standard library, as some of those applications may not supportUTF-8encoding.This can result in characters being displayed incorrectly or not at all.
However, in the batch file I provided in the edit section, the original console code page is saved at the beginning of the batch file, and then restored at the end of the batch file using the
chcpcommand.This means that any negative side effects of changing the console code page to
UTF-8will be limited to the duration of the batch file, and the console code page will be restored to its original value before launching a new command prompt.So, as long as you are only using the
UTF-8console code page within the batch file itself, and not piping text to other applications that do not supportUTF-8, you should not experience any negative side effects.