character conversion error......!
Moderator: DosItHelp
character conversion error......!
hi
i am using batch file to run one program but while doing that i m using § this character in .bat file.
but the problem is that when i am trying to run that .bat file, the DOS is converting the § character to another character.
why DOS is doing this?
how do i solve this?
any suggestions?
thank you.
i am using batch file to run one program but while doing that i m using § this character in .bat file.
but the problem is that when i am trying to run that .bat file, the DOS is converting the § character to another character.
why DOS is doing this?
how do i solve this?
any suggestions?
thank you.
Re: character conversion error......!
It's because Windows works with ANSI (ACP) while the console window works with ASCII (OEMCP) for compatibility reasons with DOS or whatever.
It's always a good idea to use only the default ASCII characters which are the same in ANSI. Since I don't know your default ANSI code page it's difficult for me to suggest a possible solution.
Regards
aGerman
It's always a good idea to use only the default ASCII characters which are the same in ANSI. Since I don't know your default ANSI code page it's difficult for me to suggest a possible solution.
Regards
aGerman
Re: character conversion error......!
As aGerman said, it depends on your system code page.
Anyway, try using this character and see what it outputs.
Anyway, try using this character and see what it outputs.
Code: Select all
õ
Re: character conversion error......!
i am using command prompt Microsoft Windows XP [Version 5.1.2600].
i am using that character as password in batch file.
that batch file contains
wget ftp://username:password§§@ftp.xxx.xx
wget is the software i am using to to download file using ftp.
but i am not able to login on that machine because of password.
if i type it manually it works but it fails if i use it in batch file
i am using that character as password in batch file.
that batch file contains
wget ftp://username:password§§@ftp.xxx.xx
wget is the software i am using to to download file using ftp.
but i am not able to login on that machine because of password.
if i type it manually it works but it fails if i use it in batch file
Re: character conversion error......!
as Fawers said i tried õ but this character was converted to ⌡
Re: character conversion error......!
Then you might want to try a plain text editor with OEM code page support.
I use and recommend PSPad.
I use and recommend PSPad.
Re: character conversion error......!
Run that batch code to read the ACP in the registry and tell us the 2 numbers it displays.
Regards
aGerman
@echo off
chcp
for /f "tokens=2*" %%i in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage" /v "ACP"') do set /a acp=%%j 2>nul
echo ACP: %ACP%
pause
Regards
aGerman
Re: character conversion error......!
hi aGerman
it displayed this information.
Active code page: 437
ACP: 1252
it displayed this information.
Active code page: 437
ACP: 1252
Re: character conversion error......!
hi Fawers
i tried with that editor.
i copied that code in new file of the PSpad and saved it as .bat file still it is not working.
i tried with that editor.
i copied that code in new file of the PSpad and saved it as .bat file still it is not working.
Re: character conversion error......!
Code: Select all
@echo off
>nul chcp 1252
set "p=§"
:: apply the variable
>"test.txt" echo %p%
start "" notepad "test.txt"
:: display the variable
>nul chcp 437
echo %p%
pause
Regards
aGerman
Re: character conversion error......!
hi aGerman
thnks man....!
error solved...!
it works great...!
Hats off to you...!
thnks man....!
error solved...!
it works great...!
Hats off to you...!
Re: character conversion error......!
hi aGerman,
your solution worked great.
can u tell me what did you do by asking me those numbers?
what about first program? what u did there?
what those numbers indicates?
and what about second program?
what you are doing over there?
your solution worked great.
can u tell me what did you do by asking me those numbers?
what about first program? what u did there?
what those numbers indicates?
and what about second program?
what you are doing over there?
Re: character conversion error......!
I'll try to cut a long story short ...
The most text editors work with the default ANSI codepage (Windows-1252 in your case). Each character is represented as 8 bits (a combination of either 0 or 1). Have a look at the link. In the table you'll find character "§" in row A and column 7. That means A7 is the hexadecimal representation of that character in codepage 1252. Hence the following 8 bits (= 1 byte) are written to the file: 10100111.
The cmd.exe reads that byte and tries to translate it to a character. Cmd.exe works with ASCII though. It's codepage 437 in your case. Have a look at that table and find the character in row A and column 7
Now you should understand how it works. The content of the file is exactly the same but the character interpretation is completely different.
What I did in my first code is simple. The CHCP command without an argument displays the current codepage of your batch window (ASCII). Inside of the FOR /F loop I queried the registry to get the default ANSI codepage.
In the second code I applied these codepages. First I changed the codepage of the batch window to ANSI. Now the byte 10100111 is interpreted as § and assigned to variable p.
When I changed back to ASCII an internal process in cmd.exe converts the variable and you can display the § in the batch window.
Regards
aGerman
The most text editors work with the default ANSI codepage (Windows-1252 in your case). Each character is represented as 8 bits (a combination of either 0 or 1). Have a look at the link. In the table you'll find character "§" in row A and column 7. That means A7 is the hexadecimal representation of that character in codepage 1252. Hence the following 8 bits (= 1 byte) are written to the file: 10100111.
The cmd.exe reads that byte and tries to translate it to a character. Cmd.exe works with ASCII though. It's codepage 437 in your case. Have a look at that table and find the character in row A and column 7
Now you should understand how it works. The content of the file is exactly the same but the character interpretation is completely different.
What I did in my first code is simple. The CHCP command without an argument displays the current codepage of your batch window (ASCII). Inside of the FOR /F loop I queried the registry to get the default ANSI codepage.
In the second code I applied these codepages. First I changed the codepage of the batch window to ANSI. Now the byte 10100111 is interpreted as § and assigned to variable p.
When I changed back to ASCII an internal process in cmd.exe converts the variable and you can display the § in the batch window.
Regards
aGerman
Re: character conversion error......!
Even though aGerman has already given you a complete, specific answer, I'll reply to this post of yours:
I forgot to say that you have to adjust the formatting.
prash11 wrote:hi Fawers
i tried with that editor.
i copied that code in new file of the PSpad and saved it as .bat file still it is not working.
I forgot to say that you have to adjust the formatting.