What encoding/code page is cmd.exe using? - windows
When I open cmd.exe in Windows, what encoding is it using?
How can I check which encoding it is currently using? Does it depend on my regional setting or are there any environment variables to check?
What happens when you type a file with a certain encoding? Sometimes I get garbled characters (incorrect encoding used) and sometimes it kind of works. However I don't trust anything as long as I don't know what's going on. Can anyone explain?
Yes, it’s frustrating—sometimes type and other programs
print gibberish, and sometimes they do not.
First of all, Unicode characters will only display if the
current console font contains the characters. So use
a TrueType font like Lucida Console instead of the default Raster Font.
But if the console font doesn’t contain the character you’re trying to display,
you’ll see question marks instead of gibberish. When you get gibberish,
there’s more going on than just font settings.
When programs use standard C-library I/O functions like printf, the
program’s output encoding must match the console’s output encoding, or
you will get gibberish. chcp shows and sets the current codepage. All
output using standard C-library I/O functions is treated as if it is in the
codepage displayed by chcp.
Matching the program’s output encoding with the console’s output encoding
can be accomplished in two different ways:
A program can get the console’s current codepage using chcp or
GetConsoleOutputCP, and configure itself to output in that encoding, or
You or a program can set the console’s current codepage using chcp or
SetConsoleOutputCP to match the default output encoding of the program.
However, programs that use Win32 APIs can write UTF-16LE strings directly
to the console with
WriteConsoleW.
This is the only way to get correct output without setting codepages. And
even when using that function, if a string is not in the UTF-16LE encoding
to begin with, a Win32 program must pass the correct codepage to
MultiByteToWideChar.
Also, WriteConsoleW will not work if the program’s output is redirected;
more fiddling is needed in that case.
type works some of the time because it checks the start of each file for
a UTF-16LE Byte Order Mark
(BOM), i.e. the bytes 0xFF 0xFE.
If it finds such a
mark, it displays the Unicode characters in the file using WriteConsoleW
regardless of the current codepage. But when typeing any file without a
UTF-16LE BOM, or for using non-ASCII characters with any command
that doesn’t call WriteConsoleW—you will need to set the
console codepage and program output encoding to match each other.
How can we find this out?
Here’s a test file containing Unicode characters:
ASCII abcde xyz
German äöü ÄÖÜ ß
Polish ąęźżńł
Russian абвгдеж эюя
CJK 你好
Here’s a Java program to print out the test file in a bunch of different
Unicode encodings. It could be in any programming language; it only prints
ASCII characters or encoded bytes to stdout.
import java.io.*;
public class Foo {
private static final String BOM = "\ufeff";
private static final String TEST_STRING
= "ASCII abcde xyz\n"
+ "German äöü ÄÖÜ ß\n"
+ "Polish ąęźżńł\n"
+ "Russian абвгдеж эюя\n"
+ "CJK 你好\n";
public static void main(String[] args)
throws Exception
{
String[] encodings = new String[] {
"UTF-8", "UTF-16LE", "UTF-16BE", "UTF-32LE", "UTF-32BE" };
for (String encoding: encodings) {
System.out.println("== " + encoding);
for (boolean writeBom: new Boolean[] {false, true}) {
System.out.println(writeBom ? "= bom" : "= no bom");
String output = (writeBom ? BOM : "") + TEST_STRING;
byte[] bytes = output.getBytes(encoding);
System.out.write(bytes);
FileOutputStream out = new FileOutputStream("uc-test-"
+ encoding + (writeBom ? "-bom.txt" : "-nobom.txt"));
out.write(bytes);
out.close();
}
}
}
}
The output in the default codepage? Total garbage!
Z:\andrew\projects\sx\1259084>chcp
Active code page: 850
Z:\andrew\projects\sx\1259084>java Foo
== UTF-8
= no bom
ASCII abcde xyz
German ├ñ├Â├╝ ├ä├û├£ ├ƒ
Polish ąęźżńł
Russian ð░ð▒ð▓ð│ð┤ðÁð ÐìÐÄÐÅ
CJK õ¢áÕÑ¢
= bom
´╗┐ASCII abcde xyz
German ├ñ├Â├╝ ├ä├û├£ ├ƒ
Polish ąęźżńł
Russian ð░ð▒ð▓ð│ð┤ðÁð ÐìÐÄÐÅ
CJK õ¢áÕÑ¢
== UTF-16LE
= no bom
A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ♣☺↓☺z☺|☺D☺B☺
R u s s i a n 0♦1♦2♦3♦4♦5♦6♦ M♦N♦O♦
C J K `O}Y
= bom
■A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ♣☺↓☺z☺|☺D☺B☺
R u s s i a n 0♦1♦2♦3♦4♦5♦6♦ M♦N♦O♦
C J K `O}Y
== UTF-16BE
= no bom
A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ☺♣☺↓☺z☺|☺D☺B
R u s s i a n ♦0♦1♦2♦3♦4♦5♦6 ♦M♦N♦O
C J K O`Y}
= bom
■ A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ☺♣☺↓☺z☺|☺D☺B
R u s s i a n ♦0♦1♦2♦3♦4♦5♦6 ♦M♦N♦O
C J K O`Y}
== UTF-32LE
= no bom
A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ♣☺ ↓☺ z☺ |☺ D☺ B☺
R u s s i a n 0♦ 1♦ 2♦ 3♦ 4♦ 5♦ 6♦ M♦ N
♦ O♦
C J K `O }Y
= bom
■ A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ♣☺ ↓☺ z☺ |☺ D☺ B☺
R u s s i a n 0♦ 1♦ 2♦ 3♦ 4♦ 5♦ 6♦ M♦ N
♦ O♦
C J K `O }Y
== UTF-32BE
= no bom
A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ☺♣ ☺↓ ☺z ☺| ☺D ☺B
R u s s i a n ♦0 ♦1 ♦2 ♦3 ♦4 ♦5 ♦6 ♦M ♦N
♦O
C J K O` Y}
= bom
■ A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ☺♣ ☺↓ ☺z ☺| ☺D ☺B
R u s s i a n ♦0 ♦1 ♦2 ♦3 ♦4 ♦5 ♦6 ♦M ♦N
♦O
C J K O` Y}
However, what if we type the files that got saved? They contain the exact
same bytes that were printed to the console.
Z:\andrew\projects\sx\1259084>type *.txt
uc-test-UTF-16BE-bom.txt
■ A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ☺♣☺↓☺z☺|☺D☺B
R u s s i a n ♦0♦1♦2♦3♦4♦5♦6 ♦M♦N♦O
C J K O`Y}
uc-test-UTF-16BE-nobom.txt
A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ☺♣☺↓☺z☺|☺D☺B
R u s s i a n ♦0♦1♦2♦3♦4♦5♦6 ♦M♦N♦O
C J K O`Y}
uc-test-UTF-16LE-bom.txt
ASCII abcde xyz
German äöü ÄÖÜ ß
Polish ąęźżńł
Russian абвгдеж эюя
CJK 你好
uc-test-UTF-16LE-nobom.txt
A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ♣☺↓☺z☺|☺D☺B☺
R u s s i a n 0♦1♦2♦3♦4♦5♦6♦ M♦N♦O♦
C J K `O}Y
uc-test-UTF-32BE-bom.txt
■ A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ☺♣ ☺↓ ☺z ☺| ☺D ☺B
R u s s i a n ♦0 ♦1 ♦2 ♦3 ♦4 ♦5 ♦6 ♦M ♦N
♦O
C J K O` Y}
uc-test-UTF-32BE-nobom.txt
A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ☺♣ ☺↓ ☺z ☺| ☺D ☺B
R u s s i a n ♦0 ♦1 ♦2 ♦3 ♦4 ♦5 ♦6 ♦M ♦N
♦O
C J K O` Y}
uc-test-UTF-32LE-bom.txt
A S C I I a b c d e x y z
G e r m a n ä ö ü Ä Ö Ü ß
P o l i s h ą ę ź ż ń ł
R u s s i a n а б в г д е ж э ю я
C J K 你 好
uc-test-UTF-32LE-nobom.txt
A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ♣☺ ↓☺ z☺ |☺ D☺ B☺
R u s s i a n 0♦ 1♦ 2♦ 3♦ 4♦ 5♦ 6♦ M♦ N
♦ O♦
C J K `O }Y
uc-test-UTF-8-bom.txt
´╗┐ASCII abcde xyz
German ├ñ├Â├╝ ├ä├û├£ ├ƒ
Polish ąęźżńł
Russian ð░ð▒ð▓ð│ð┤ðÁð ÐìÐÄÐÅ
CJK õ¢áÕÑ¢
uc-test-UTF-8-nobom.txt
ASCII abcde xyz
German ├ñ├Â├╝ ├ä├û├£ ├ƒ
Polish ąęźżńł
Russian ð░ð▒ð▓ð│ð┤ðÁð ÐìÐÄÐÅ
CJK õ¢áÕÑ¢
The only thing that works is UTF-16LE file, with a BOM, printed to the
console via type.
If we use anything other than type to print the file, we get garbage:
Z:\andrew\projects\sx\1259084>copy uc-test-UTF-16LE-bom.txt CON
■A S C I I a b c d e x y z
G e r m a n õ ÷ ³ ─ Í ▄ ▀
P o l i s h ♣☺↓☺z☺|☺D☺B☺
R u s s i a n 0♦1♦2♦3♦4♦5♦6♦ M♦N♦O♦
C J K `O}Y
1 file(s) copied.
From the fact that copy CON does not display Unicode correctly, we can
conclude that the type command has logic to detect a UTF-16LE BOM at the
start of the file, and use special Windows APIs to print it.
We can see this by opening cmd.exe in a debugger when it goes to type
out a file:
After type opens a file, it checks for a BOM of 0xFEFF—i.e., the bytes
0xFF 0xFE in little-endian—and if there is such a BOM, type sets an
internal fOutputUnicode flag. This flag is checked later to decide
whether to call WriteConsoleW.
But that’s the only way to get type to output Unicode, and only for files
that have BOMs and are in UTF-16LE. For all other files, and for programs
that don’t have special code to handle console output, your files will be
interpreted according to the current codepage, and will likely show up as
gibberish.
You can emulate how type outputs Unicode to the console in your own programs like so:
#include <stdio.h>
#define UNICODE
#include <windows.h>
static LPCSTR lpcsTest =
"ASCII abcde xyz\n"
"German äöü ÄÖÜ ß\n"
"Polish ąęźżńł\n"
"Russian абвгдеж эюя\n"
"CJK 你好\n";
int main() {
int n;
wchar_t buf[1024];
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
n = MultiByteToWideChar(CP_UTF8, 0,
lpcsTest, strlen(lpcsTest),
buf, sizeof(buf));
WriteConsole(hConsole, buf, n, &n, NULL);
return 0;
}
This program works for printing Unicode on the Windows console using the
default codepage.
For the sample Java program, we can get a little bit of correct output by
setting the codepage manually, though the output gets messed up in weird ways:
Z:\andrew\projects\sx\1259084>chcp 65001
Active code page: 65001
Z:\andrew\projects\sx\1259084>java Foo
== UTF-8
= no bom
ASCII abcde xyz
German äöü ÄÖÜ ß
Polish ąęźżńł
Russian абвгдеж эюя
CJK 你好
ж эюя
CJK 你好
你好
好
�
= bom
ASCII abcde xyz
German äöü ÄÖÜ ß
Polish ąęźżńł
Russian абвгдеж эюя
CJK 你好
еж эюя
CJK 你好
你好
好
�
== UTF-16LE
= no bom
A S C I I a b c d e x y z
…
However, a C program that sets a Unicode UTF-8 codepage:
#include <stdio.h>
#include <windows.h>
int main() {
int c, n;
UINT oldCodePage;
char buf[1024];
oldCodePage = GetConsoleOutputCP();
if (!SetConsoleOutputCP(65001)) {
printf("error\n");
}
freopen("uc-test-UTF-8-nobom.txt", "rb", stdin);
n = fread(buf, sizeof(buf[0]), sizeof(buf), stdin);
fwrite(buf, sizeof(buf[0]), n, stdout);
SetConsoleOutputCP(oldCodePage);
return 0;
}
does have correct output:
Z:\andrew\projects\sx\1259084>.\test
ASCII abcde xyz
German äöü ÄÖÜ ß
Polish ąęźżńł
Russian абвгдеж эюя
CJK 你好
The moral of the story?
type can print UTF-16LE files with a BOM regardless of your current codepage
Win32 programs can be programmed to output Unicode to the console, using
WriteConsoleW.
Other programs which set the codepage and adjust their output encoding accordingly can print Unicode on the console regardless of what the codepage was when the program started
For everything else you will have to mess around with chcp, and will probably still get weird output.
Type
chcp
to see your current code page (as Dewfy already said).
Use
nlsinfo
to see all installed code pages and find out what your code page number means.
You need to have Windows Server 2003 Resource kit installed (works on Windows XP) to use nlsinfo.
To answer your second query re. how encoding works, Joel Spolsky wrote a great introductory article on this. Strongly recommended.
I've been frustrated for long by Windows code page issues, and the C programs portability and localisation issues they cause. The previous posts have detailed the issues at length, so I'm not going to add anything in this respect.
To make a long story short, eventually I ended up writing my own UTF-8 compatibility library layer over the Visual C++ standard C library. Basically this library ensures that a standard C program works right, in any code page, using UTF-8 internally.
This library, called MsvcLibX, is available as open source at https://github.com/JFLarvoire/SysToolsLib. Main features:
C sources encoded in UTF-8, using normal char[] C strings, and standard C library APIs.
In any code page, everything is processed internally as UTF-8 in your code, including the main() routine argv[], with standard input and output automatically converted to the right code page.
All stdio.h file functions support UTF-8 pathnames > 260 characters, up to 64 KBytes actually.
The same sources can compile and link successfully in Windows using Visual C++ and MsvcLibX and Visual C++ C library, and in Linux using gcc and Linux standard C library, with no need for #ifdef ... #endif blocks.
Adds include files common in Linux, but missing in Visual C++. Ex: unistd.h
Adds missing functions, like those for directory I/O, symbolic link management, etc, all with UTF-8 support of course :-).
More details in the MsvcLibX README on GitHub, including how to build the library and use it in your own programs.
The release section in the above GitHub repository provides several programs using this MsvcLibX library, that will show its capabilities. Ex: Try my which.exe tool with directories with non-ASCII names in the PATH, searching for programs with non-ASCII names, and changing code pages.
Another useful tool there is the conv.exe program. This program can easily convert a data stream from any code page to any other. Its default is input in the Windows code page, and output in the current console code page. This allows to correctly view data generated by Windows GUI apps (ex: Notepad) in a command console, with a simple command like: type WINFILE.txt | conv
This MsvcLibX library is by no means complete, and contributions for improving it are welcome!
Command CHCP shows the current codepage. It has three digits: 8xx and is different from Windows 12xx. So typing a English-only text you wouldn't see any difference, but an extended codepage (like Cyrillic) will be printed wrongly.
In Java I used encoding "IBM850" to write the file. That solved the problem.
You can control the code page simply by creating a file %HOMEPATH%\init.cmd.
Mine says:
#ECHO OFF
CHCP 65001 > nul
Related
Why does \lstinputlisting show up as raw text in my latex file?
I have the .txt file encoded as UTF-8, I imported the package "\usepackage{listings}", I referenced it properly but yet it wont show up as the code but only prints out the "\ l s t i n p u t l i s t i n g { f i g u r e s / C o d e S t a t e m a c h i n e . t x t }" part. What am I doing wrong here? \begin{lstlisting}[language=Matlab, caption={Code Statemachine}, label={lst:CodeStatemachine}, captionpos=b] \lstinputlisting{figures/CodeStatemachine.txt} \end{lstlisting} I also tried just pasting the Code itself, however it just cuts off after it fills the A4 page..
The correct syntax is \begin{lstlisting}[language=Matlab, caption={Code Statemachine}, label={lst:CodeStatemachine}, captionpos=b] Code goes here \end{lstlisting} or \lstinputlisting[language=Matlab, caption={Code Statemachine}, label={lst:CodeStatemachine}, captionpos=b]{test.txt} but not both at the same time.
How to recognize what coding language is used when notepad++ shows strange symbols?
I opened this file in notepad++, but it does only show gibberish in the first 2 lines of the file. So when I change some values that are shown in normal text, and I save it, the file has become unreadable for the original program. How do I detect what language this is? I've tried multiple encode/decoders online and notepad++ and asked a developer for help but he didn't know the answer for this. W v e F i l e ¸›U P r o j e c t . x m l Àv Yí õ:NQÿ ## Ö Ø Àv 0 0í # Xî }ž î …Œ# }ž î ê¶C Èî Èî €î …Œ# ¸›U }ž ¸›U 0Ò› Øî (A €î …Œ# X[x (A Øî }ž Öí î ¸›U }ž Öí ¸›U Q‰ˆ Ðì #[x 8ï p õ =k File is corrupted when I open it with the original program.
Shell script - iterate over space separated words/characters (in zsh)
I am having some trouble figuring out how to iterate over space separated words/characters in a shell script. For instance I would like to iterate over a variable containing the characters in the alphabet separated by a space. NOTE: The result should be the same even if the alphabet variable contained space separated strings instead of characters, i.e "aa bb cc ..." instead of "a b c .." I have tried a lot of the alternatives provided from: How to split a line into words separated by one or more spaces in bash? Example: local alphabet="a b c d e f g h i j k l m n o p q r s t u v w x y z" local index="0" for character in $alphabet; do index=$((++index)) echo "$index. $character" # Possibility to do some more stuff done Expected/Desired output: 1. a 2. b 3. c and so on.. Result: 1. a b c d e f g h i j k l m n o p q r s t u v w x y z Additional tests(without success): #################################################################### local alphabet="a b c d e f g h i j k l m n o p q r s t u v w x y z" local index="0" for character in ${alphabet[#]}; do index=$((++index)) echo "$index. $character" # Possibility to do some more stuff done #################################################################### local alphabet="a b c d e f g h i j k l m n o p q r s t u v w x y z" local alphabetArray=( ${alphabet} ) local index="0" for character in "${alphabetArray[#]}"; do index=$((++index)) echo "$index. $character" # Possibility to do some more stuff done #################################################################### local alphabet="a b c d e f g h i j k l m n o p q r s t u v w x y z" local alphabetArray=( ${alphabet} ) local index="0" for character in ${alphabetArray}; do index=$((++index)) echo "$index. $character" # Possibility to do some more stuff done Could someone provide a solution on how to solve this(I would prefer a solution that iterates the alphabet variable without explicitly using an index variable, i.e $alphabet[index] )?
Thanks for your help. I discovered the error thanks to your feedback. I thought that it was irrelevant when I posted this question but I was experimenting with functions in my .zshrc file. Hence I was using (just my assumption) the zsh interpreter and not the sh or bash interpreter. By realizing that this could be a potential problem, I googled and found the following How to iterate through string one word at a time in zsh So I tested the following and it works as expected: setopt shwordsplit local alphabet="a b c d e f g h i j k l m n o p q r s t u v w x y z" local index="0" for character in $alphabet; do index=$(($index+1)) echo "$index. $character" # Possibility to do some more stuff done unsetopt shwordsplit NOTE: index=$((++$index)) and/or index=$(($index++)) Doesn't seem to work as I expected in zsh. ... The little gritty details, I should have used: ((++index)) or ((index++)) instead of index=$((++$index))
Try this IFS=$' \t\n' local alphabet="a b c d e f g h i j k l m n o p q r s t u v w x y z" local index="0" for character in $alphabet; do index=$((++index)) echo "$index. $character" # Possibility to do some more stuff done Hope it helps
Capitalize first letter of a filename
I have some files in a folder and would like to uppercase the first letter of all the filenames with a certain extension using a batch script in windows. example cap only *.m before: foo.m bar.m picture.jpg after: Foo.m Bar.m picture.jpg
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( ren %%a*.m %%a* >nul 2>&1 ) Check also this -> https://superuser.com/questions/475874/how-does-the-windows-rename-command-interpret-wildcards
Change output of pause command in batch script
I'm writing a Windows batch script. By default, the pause command will pause the script and display the text "Press any key to continue...". How do I modify this text to display my own text to the user?
You could hide the text from the pause command by using this: pause >nul Then you could echo your own message to tell the user it has paused: echo The batch file has paused So the full script might look like this: #echo off echo Hello World! echo The batch file has paused pause >nul
Here's a one-liner pause>nul|set/p =any key to exit ... It's slightly shorter (one less 'nul') than Aacini's solution: set/p<nul =any key to exit ...&pause>nul and, with the 'pause' first, I think that it's a little clearer what the intent is. With both cursor stays on the same line ANY key works, not just 'enter' Neither are as good, however, as the hypothetical pause/t any key to exit ... It's hard to believe that 'pause' has survived 35 years without this ability ;-) The solutions with 'echo' have the possibly undesirable trailing new-line, but do provide for multiple lines of text: Pause>nul|(echo All your bases &echo are belong to us &echo Press any key to die...) bv
"Not really what I was looking for, I was wondering whether there was a way of actually changing the output text of the Pause command, not just a workaround to it." – Hashim Yes, you can! But you must be aware that PAUSE is an internal command of CMD.EXE program, so, to modify the message that PAUSE show, you must modify CMD.EXE file. To do that, you must use an editor that may modify binary files. I used XVI32 program via these steps: 1- Copy CMD.EXE file to a new folder created for this purpose: COPY %COMSPEC% 2- Edit the copy of CMD.EXE with XVI32.EXE program: 2.1- Locate the message you want. Messages are stored in 16-bits elements with the high byte equal zero. To locate a message: 2.1.1- In Search> Find> Text string> enter the message you want. 2.1.2- Convert Text -> Hex 2.1.3- Insert a zero after each letter-value 2.1.4- Press Ok 2.2- Modify the message for the new one. Modify existent letters only and keep zeros in place. Note that you can NOT extend any message. 2.3- End the edition and save the modified file. You may now run CMD.EXE to get the modified PAUSE message. I made a test of this procedure: C:\DOCUME~1\Antonio\MYDOCU~1\My Webs\XVI32 Hex File Editor >pause Press any key to continue . . . C:\DOCUME~1\Antonio\MYDOCU~1\My Webs\XVI32 Hex File Editor >cmd Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\DOCUME~1\Antonio\MYDOCU~1\My Webs\XVI32 Hex File Editor >pause Oprime una tecla para seguir. . Notes to everyone that read this answer: NOTE 1: Please, don't post that comment saying that modifying CMD.EXE file must NEVER be done! I think the same. I just posted this answer so the OP realized what he really asked for... NOTE 2: The reviewing of CMD.EXE file with a text editor, like Notepad, is very interesting. You may see all the internal commands, interesting details (like =ExitCode and =ExitCodeAscii variables), all the error messages, etc. For example, these are the internal commands: C O L O R T I T L E C H D I R C L S C M D E X T V E R S I O N D E F I N E D C O P Y P A T H P R O M P T P U S H D P O P D A S S O C F T Y P E D A T E D E L D I R E C H O E N D L O C A L E R A S E E R R O R L E V E L E X I T E X I S T B R E A K F O R G O T O I F K E Y S M K D I R M D N O T P A U S E R D R E M M O V E R E N A M E R E N R M D I R S E T S E T L O C A L S H I F T S T A R T T I M E T Y P E V E R I F Y V E R V O L = , ; + / [ ] " : . \ P A T H E X T P A T H P R O M P T F O R / ? I F / ? R E M / ? % s % s % s / A / P : E O F f d p n x s a t z D O / L / D / F / R I N E L S E ( % s ) % s % s % s % s % c % c % s % s & ( ) [ ] { } ^ = ; ! % ' + , ` ~
There is no way to change the text of the pause command. However you might want to look at the choice command. You can change the text it prints. The only downside is that you need to provide a list of acceptable characters.
Already many solutions. Another variation that makes some sense: echo Hit any key to continue...&pause>nul
Another dirty solution would be something like this, SET /P =Press enter to return to the menu . . . GOTO :menu The benefit of this is that the cursor stays on the same line as the message, just like with the PAUSE command. The downside is that it only listens to the enter key.
Here’s another trick Pause. >nul | echo. Press something to continue
Starting from Windows 2000 (so, not XP) you can use the choice command which is far more powerful than either pause or set /p. Besides being able to specify your own prompt text, you can also require the user to type a specific key, and only that key, instead of being limited to, and requiring, [Enter] to be pressed. Also, you can prompt the user to press a number of different keys and take action based on which key was pressed. Type choice /? for help, or read more about it here: Wikipedia: choice (command)
You could do it like this! #echo off echo Hello World! echo: echo Press 1 to continue set /p letter= if %letter% == 1 goto a ;or instead of goto you could write start and the file or website you want to start pause >nul :a cls echo BYE NOW! pause >nul
pause|echo text you want displayed
Since I dont see it suggested and every dog on the internet has had a go, but me. This may not have worked under XP, as required by OP, but is valid for any newer system like my current Win7 :-) Dirty version (no message) |keys ON does nothing, but block the press any key ... timeout -1|Keys ON can be used for message after #timeout -1|Keys ON&echo I'm back This one will pause and show a response until accepted then return to prompt/next cmd line #timeout -1|Echo Hello Padawan %userprofile:~9%, Press a key, you can! :on any keys #echo Welcome to the dark side