View unanswered posts | View active topics It is currently 19 Apr 2014 21:41



Post new topic Reply to topic  [ 14 posts ] 
character conversion error......! 
Author Message

Joined: 27 Apr 2012 01:38
Posts: 21
Post 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.


27 Apr 2012 01:41
Profile
Expert

Joined: 22 Jan 2010 18:01
Posts: 1683
Location: Germany
Post 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


27 Apr 2012 04:38
Profile

Joined: 08 Apr 2012 17:11
Posts: 187
Post Re: character conversion error......!
As aGerman said, it depends on your system code page.

Anyway, try using this character and see what it outputs.
Code:
õ


27 Apr 2012 06:16
Profile WWW

Joined: 27 Apr 2012 01:38
Posts: 21
Post 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


27 Apr 2012 06:17
Profile

Joined: 27 Apr 2012 01:38
Posts: 21
Post Re: character conversion error......!
as Fawers said i tried õ but this character was converted to ⌡


27 Apr 2012 06:19
Profile

Joined: 08 Apr 2012 17:11
Posts: 187
Post Re: character conversion error......!
Then you might want to try a plain text editor with OEM code page support.

I use and recommend PSPad.


27 Apr 2012 06:37
Profile WWW
Expert

Joined: 22 Jan 2010 18:01
Posts: 1683
Location: Germany
Post Re: character conversion error......!
Run that batch code to read the ACP in the registry and tell us the 2 numbers it displays.
Quote:
@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


27 Apr 2012 06:40
Profile

Joined: 27 Apr 2012 01:38
Posts: 21
Post Re: character conversion error......!
hi aGerman
it displayed this information.
Active code page: 437
ACP: 1252


27 Apr 2012 06:45
Profile

Joined: 27 Apr 2012 01:38
Posts: 21
Post 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.


27 Apr 2012 06:51
Profile
Expert

Joined: 22 Jan 2010 18:01
Posts: 1683
Location: Germany
Post Re: character conversion error......!
Code:
@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


27 Apr 2012 07:35
Profile

Joined: 27 Apr 2012 01:38
Posts: 21
Post Re: character conversion error......!
hi aGerman
thnks man....!
error solved...!
it works great...!
Hats off to you...!


27 Apr 2012 07:40
Profile

Joined: 27 Apr 2012 01:38
Posts: 21
Post 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?


27 Apr 2012 07:55
Profile
Expert

Joined: 22 Jan 2010 18:01
Posts: 1683
Location: Germany
Post 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 :wink:
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


27 Apr 2012 09:51
Profile

Joined: 08 Apr 2012 17:11
Posts: 187
Post Re: character conversion error......!
Even though aGerman has already given you a complete, specific answer, I'll reply to this post of yours:
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.
Image


Image


27 Apr 2012 10:22
Profile WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.