Ive tried pasting this character: ☢ into a txt file,but when I use TYPE,it doesn't show the symbol? Is there a certain code page?
Tried different encoding options.
I know about the CHCP command and tried different pages.
As Josep indicates, the text file containing the UTF-8 character has to be encoded in UTF-8 with BOM.
Also, your console font has to include that character. The default fonts don't. I just tested DejaVu Sans Mono, and it works. See this page for instructions on how to add a TrueType font to the cmd console.
Finally, you can get around messing with the code page garbage by invoking powershell. That way you don't have to mess with scraping the current code page, changing it to 65001, doing your thing, then restoring back to original. Just do this:
powershell "gc nuke.txt"
... where nuke.txt contains ☢
Edit: Since you're unable to install new fonts on your computer, the only solution is ascii art.
___
\_/
.--,O.--,
\/ \/
You have to make sure your file has the UTF8 BOM (Use Notepad++ or the option suggested in the answers below), then you may need to change the character set of your console with chcp 65001, see this answers for more information:
How to make Unicode charset in cmd.exe by default?
How to convert a batch file stored in utf-8 to something that works via another batch file and run it
Related
Hoping someone can help.
I have a batch job (Windows env) which simply copies a file to another folder.
copy "\\ACP-MS-NAS21\Global\MEC Daily Productivity\Business Analysts\Master_List\HCP_Master_List.xlsx" ^
"\\ACP-MS-NAS21\Global\CSD [?] DWP Medical Services\CSL_CSD_DB\Master_List"
But I get the following error:
The filename, directory name, or volume label syntax is incorrect.
I can see there's an en dash in the file path which I believe is causing the problem.
Is there any way to have a wildcard in the file path or any other way the job can recognise this?
Thanks in advance.
PS. newbie at batch programming, coding etc, so please can explanations be in plain English. Many thanks
The command-line windows (and by extension - BAT files) operate in OEM codepage by default. Which exact codepage is defined by your OS settings (Language for non-Unicode programs or similar). Therefore you cannot normally use anything outside ASCII or whatever codepage you have.
Save script as UTF-8
To use those characters you will need to work in a codepage that actually has them. UTF-8 is the best one for this tasks (and probably the only one that will work in your case).
First, save your script as UTF-8. In notepad you can select codepage from save as menu.
If your editor does not allow you to select UTF-8 (no BOM) leave first line of your BAT file blank as some editors may preface your file a special header called BOM that helps detecting codepage. If it does and you leave 1st line blank you will get a Bad command or file name error as soon as your script starts but this won't prevent it from running properly.
Select UTF-8 codepage
Now, your script is in UTF-8 but windows command processor will still execute it as if it was in ASCII, thus corrupting all special characters. To specify our encoding we need to add following command, preferentially as a first non-blank line of your script, including comments (those may have non-ASCII characters in them - with unpredictable results)
CHCP 65001
CHCP changes current codepage to 65001 which is internal codepage number for UTF-8.
This works because latin letters and numbers in UTF-8 have the same encoding as in ASCII and OEM codepages. Thus your scripts starts executing in OEM codepage, but since CHCP 65001 command itself does not have non-ASCII characters it understood correctly. All following commands will be executed in UTF-8 and may have non-ASCII characters.
You may now insert em-dash into the filename and it won't be replaced with ? upon saving.
Set UTF-8 font
Unfortunately default console window font does not display UTF-8 correctly so you won't be able to see non-ASCII characters correctly.
To solve this you should right-click command-line window title bar, select properties, and change font to UNICODE one. Consolas, Lucida Console and Courier New should work.
Thanks for all the responses.
I've had to make a design change to my DB so have managed to get around the need to do this now (phew :))
Thanks again
I have problems controlling character code pages in a Windows cmd window, or rather in DOS scripts (.bat files) I use for certain tasks on my Windows 7 office computer.
Here is the problem:
One of my scripts is used to open certain files in their respective programmes, e.g.
C:\Stuff\Büroeinrichtung\MyFile.xlsx
The crucial thing here is the u-umlaut (ü) in the directory name.
In my script I use
Start "" "C:\Stuff\Büroeinrichtung\MyFile.xlsx"
to start Excel and open the file.
This works as long as I tell my text editor (Notepad++) to encode the script using codepage 850 (Western European), as this is what the cmd windows on my machine use by default.
However, I want to be able to use scripts that are encoded in something else, primarily UTF-8 or UTF-8-BOM. From answers to another question posted here I learned that principally I can set a command in the script for the cmd window to change the codepage, e.g. chcp 65001 for UTF-8. So my script would then look like
chcp 65001
pause :: this is here just to have some visual control while testing
Start "" "C:\Stuff\Büroeinrichtung\MyFile.xlsx"
pause :: dito
But: whatever I do, I do not get this running. The cmd window nicely accepts the change to the codepage, then stops due to pause (in Line 2), but on hitting "enter" to continue I
either get an alert that something is wrong with the ü (other, fancy, characters displayed), or
I get an alert that a directory of that name wasn't found (again obviously something wrong with the ü the actual bits of which seem to respresent something else) or
the cmd window just disappears (apparently crashed, and apparently never reaching Line 4 where a new pause would halt it).
I tried all possible combinations of codepages called in the script and various encodings for the script file (.bat) itself but did not get anywhere.
So, to put the long story short: What do I have to do, in a script encoded in UTF-8 (or so) and going to be run on a machine using codepage 850 by default that a character ü (u-umlaut) in a directory name is to be understood in the script as exactly ü, nothing else?
I've had this small problem for quite some time now and I haven't been able to find a solution even after excessive googling.
In this guide it is described how LaTeX can be written and compiled using npp++ and nppExec together with SumatraPDF.
Through some clever scripts and the use of DDE commands (through CMCDDE.exe), it is even possible to use sumatra's ForwardSearch to jump back and forth from the .tex to the .pdf. Everything works great, unless the path to the .tex file contains a character that's not in the English alphabet (for example åäö).
The CMCDDE command then fails because the path sent to sumatra's ForwardSearch reads (for example) C:\†„” instead of C:\åäö. This has to be an encoding issue and I haven't been able to find a working solution.
So, if I have this .tex file C:\åäö\MWE.tex with
\documentclass{article}
\begin{document}
Hello World!
\end{document}
it won't open correctly when using the batch script described in the link above. These are the problematic batch file lines:
::Writes the commands that are to be executed using CMCDDE.exe (through cmcdde.tmp)
echo SUMATRA>"%~dp1build\cmcdde.tmp"
::%~dp1build transforms into C:\åäö\build for the MWE
echo control>>"%~dp1build\cmcdde.tmp"
echo [ForwardSearch("%~dp1build\%~n1.pdf", "%~f1", %2, 0, 0, 0)]>>"%~dp1build\cmcdde.tmp"
:: This gives the following line in cmcdde.tmp: [ForwardSearch("P:\Documents\†„”\build\MWE.pdf", "P:\Documents\†„”\MWE.tex", 3, 0, 0, 0)] (in ANSI encoding)
"P:\Documents\localtexmf\cmcdde.exe" #"%~dp1build\cmcdde.txt"
:: This fails because the path P:\Documents\†„”\build doesn't exist (P:\Documents\åäö\build does)
Ideas I've had and tried:
I tried changing the encoding by using chcp 65001 and chcp 865 but
haven't been able to get it to work.
I have also tried using a
search and replace
script to go through the cmcdde.tmp file before executing it but it didn't
succeed (I'm not sure which signs I should search for to exchange for
åäö, †„” or åäö or ├Ñ├ñ├ or other?)
I have also tried putting
cmd /c or cmd /a /c before the echo commands (as sort of described
here)
but it doesn't seem to make a difference.
Please let me know if something which parts of the question that are unclear.
I managed to find a solution. Turns out using the code page 1252 solves the problem.
So putting chcp 1252 at the beginning of the batch file is the solution. However, if you're using other none standard characters than me (other then the ones in the nordic alphabet), I'm guessing you might need another code page.
Experiment and test different ones until you get it working.
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.
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.
Try changing the code page of your batch file to UTF-8: Insert this line at the top of your batch file and save the file as UTF-8:
chcp 65001
Be careful though: Creating folders with non-ASCII letters can break some programs that may rely on older API of libraries, or just assume that all folder and file names are ASCII.
I am writing a batch script to go through some directories doing an specific task, something like the following:
set DBCreationScript=//Here I set the full path for the script
echo %DBCreationScript%
Problem is the path has got some latin characters (ç, ã, á) and when I run the script, the output shows strange characters, not the ones I typed in. The batch script is in ANSI encoding.
I already tried to set the script encoding to UTF-8, but apparently the batch interpreter can't handle the control characters that appear on the beggining of the file.
Any thoughts?
Save the batch file in OEM encoding (a decent editor should allow this) or change the code page prior to running it with
chcp 1252
You can also save it as UTF-8 without signature (BOM) and use
chcp 65001
but down that path lies peril and dragons await to eat you (in short: It's usually painful and has a few weird side-effects).