views:

826

answers:

1

For example, suppose I have a batch file called 'test.cmd' and it simply contains:

echo %1

I can call this directly from the command prompt with 'test.cmd some¬arg' and the result is that the string 'some¬arg' is printed.

However if I place that same call in a second batch file, called 'tester.cmd' for the sake of argument, and I call this from the command prompt the result is that the string 'some%arg' is printed.

What is it that messes up the encoding and how do I get around it? I am sure I've fixed this before, but I can't remember how...

Thanks!

+4  A: 

This is because your batch file is encoded in a different code page than cmd.exe is currently in.

In western default configurations, cmd.exe starts in CP850, but text editors usually work in CP1252 (what is often wrongly referred to as Latin-1 or ISO-8859-1).

The characters "¬" and "¼" share the same character code in these two code pages, "BC".

The solution is simple. Either encode your batch file in code page 850, or switch cmd.exe to code page 1252 by issuing chcp 1252.

Tomalak